I tried to pass the "decodedPoints" directly as Sebastian has shown in
his example without success. I don't know if Sebastien was just
showing this as a brief example of the method but, the decoded results
that I get are not setup as LatLng points that I can directly shove in
the "path" property of the Polyline.
I had to take the result and parse it as a string in order to setup a
new "path" of acceptable LatLng points. Is there an easier way of
creating the Polyline "path" with the decoded result(like in
Sebastian's example which doesn't work for me)?
Rough code I just used to make the decoded sets acceptable:
var path = routePath.getPath();//the path of the Polyline already on
the map
var points=new Array();
decodedSets=google.maps.geometry.encoding.decodePath("encodedpointstobedecoded").toString();
//get rid of the brackets
decodedSets=decodedSets.replace(/\,\(/gi, "");
decodedSets=decodedSets.replace(/\(/gi, "");
var brokenstring=decodedSets.split(")");
for(var i in brokenstring){
if(brokenstring[i].length>1){
points=brokenstring[i].split(",");
myLatLng = new google.maps.LatLng(points[0],points[1]);
path.push(myLatLng);
}
}
On Jan 13, 12:16 pm, Sebastian <[email protected]> wrote:
> To use a polyline from the Direction Web service, you need the
> google.maps.geometry.encoding.decodePath() function from the geometry
> library.
>
> Load the V3 API with:
>
> <script type="text/javascript" src="http://maps.google.com/maps/api/js?
> libraries=geometry&sensor=false">
> </script>
>
> Create the map, set markers for start and destination and so on.
>
> Replace backslashes '\' in points with '\\', it seems the levels are
> kinda ballast from V2 (?).
>
> var encodedPoints = "s}dcFlnchVz@n@vJeVpF}NzMy\\}
> KyI{AoBg@{@wKmWs@wB_AsE_@wEQkLQ}Cy@qE{@kCiBsD{_@_r@qS{\
> \mBqDoOw^mBwGOqAPyEGsAKu@eBmEOu@Eu@X}DEu@r_@osCjJyi@|
> AiH~B_NxJoe@j[kdBjLwl@rJkh@zG_]jCsOhEe\\`Iur@pBuOjAuLhAsI|
> BcPnCuNhAiEz@_B~@kA|
> AgAnLcDvBmAt@o@dBwBxEwJtI_PzBcDdE_EnVePpg@o]lKsFzJgE`EkCjCqCrB{CvAwCtBmFfAs
> B`DiEdC_CpEkClGgC`EyBrG_ETAdHuDx@YdAKhEb@jB]hAi@{EaOmDqJeEnC" ;
>
> var decodedPoints =
> google.maps.geometry.encoding.decodePath(encodedPoints) ;
>
> var encodedPolyline = new google.maps.Polyline ( {
> strokeColor: "#970E04" ,
> strokeOpacity: 1.0 ,
> strokeWeight: 2 ,
> path: decodedPoints ,
> clickable: false} );
>
> encodedPolyline.setMap(myMap);
>
> Done.
>
> HTH
> Sebastian
>
> On Dec 15 2010, 5:24 am, Christian Zambrano <[email protected]>
> wrote:
>
>
>
>
>
>
>
> > The response of a request for direction to the Google Maps Web Service
> > includes encoded polylines in the element overview_polyline. I would like to
> > display these polylines on a Javascript google map V3 but there doesn't seem
> > to be a way. Am I missing something? V2 had GPolyline which accepted encoded
> > Polylines.
>
> > Any help would be greatly appreciated.
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.