JSON is just return a string (not an array) so you just need to use
the Javascript eval() function to parse/executes that string to form
the array of LatLng.
>
> $.getJSON("routefinder", { "lat1": lat1 , "lng1": lng1 , "lat2":
> lat2 , "lng2": lng2 }, function(json) {
> var poly = new google.maps.Polyline({
> path: eval(json), // LIKE THIS
> strokeColor: "#FF0000",
> strokeOpacity: 1.0,
> strokeWeight: 2
> });
>
> poly.setMap(map);
> });
>
But I hate this because it will blindly execute any String as
Javascript.
Better way is to pass just the Lat Longitude as Data and create the
google.maps.LatLng.
"locations": [
{
"Lat": "53.369567",
"Lng": "-6.323699",
},
{
"Lat": "53.367705",
"Lng": "-6.317386"
},
{
"Lat": "53.367705"
"Lng": "-6.917386",
},
{
"Lat": "53.367705",
"Lng": "-6.47386)",
}
]
$.getJSON(routefinder,
function(data){
var myPath = new Array();
$.each(data.locations, function(i,location){
path.push(new google.maps.LatLng(location.Lat,
location.Lng))
});
var poly = new google.maps.Polyline({
path: myPath,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
poly.setMap(map);
--
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.