-1

I am trying to get from an encoded polyline to coordinates, but the original data, which produce a result, have some ascii numbers below 63, making that it is no possible to get the original latitude and longitude. For example:

http://maps.googleapis.com/maps/api/staticmap?scale=2&markers=label:S|30.17637634277344,-97.81493377685547&markers=label:E|30.1741943359375,-97.82305145263672&path=enc:eydwDnm_tQp@FD@F?F?d@C%7C@SJCHGHGDGDGTm@NHFBJDNBP@%5E@zBETHD%60K@vBJvMBzE@%60H?bA?h@@pA@Z??&size=600x600&sensor=false

Here you can see that it produce correctly the map, but the polyline contain %, 7, 5 and 6. what can I do in order to get the latitude and longitude correct using this polyline? I am using this algorithm: https://developers.google.com/maps/documentation/utilities/polylinealgorithm

thanks!

1 Answers1

0

That URL is url encoded. Before running it through the encoded polyline decoder, you need to "un-URL encode" it.

If I plug it into a URL decoder, I get

eydwDnm_tQp@FD@F?F?d@C|@SJCHGHGDGDGTm@NHFBJDNBP@^@zBETHD`K@vBJvMBzE@`H?bA?h@@pA@Z??

If I run that through the decoder, it works.

proof of concept fiddle (javascript)

code snippet:

var geocoder;
var map;

function initialize() {
  var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
  var encPoly = 'eydwDnm_tQp@FD@F?F?d@C%7C@SJCHGHGDGDGTm@NHFBJDNBP@%5E@zBETHD%60K@vBJvMBzE@%60H?bA?h@@pA@Z??';
  var polyline = new google.maps.Polyline({
    map: map,
    path: google.maps.geometry.encoding.decodePath(decodeURI(encPoly))
  });
  var bounds = new google.maps.LatLngBounds();
  for (var i = 0; i < polyline.getPath().getLength(); i++) {
    bounds.extend(polyline.getPath().getAt(i));
  }
  map.fitBounds(bounds);
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<div id="map_canvas"></div>
geocodezip
  • 158,664
  • 13
  • 220
  • 245