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 <
sebastian....@googlemail.com> 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" ;