Reputation: 5921
I'm using Google map v3 direction api
in my project.
I give cities name as a start point
and end point
for getting Distance and Time Taken for that distance.
I have another requirement to get longitude and latitude of start point which is city name.
Can I get it from direction api which is used by me to get distance and time taken in result of direction api?
If we can get latitude and longitude from result of direction api, then please help me by giving proper answer.
thanks in advance.
Upvotes: 2
Views: 1999
Reputation: 161
The response does not contain a lat/lng string. You have to get it using a function.
Using jquery this works for me.
$.each(result.routes[0].legs, function(index, route) {
alert(route.start_location.lat());
});
This will alert each starting latitude for each leg of the journey you requested.
Upvotes: 1
Reputation: 3149
From a quick look at the responses section of the directions API documentation , it looks like you can get the start_location -> lat and start_location -> lng the same way you are already getting the distance and time.
I guess that would be:
routes.legs[0].start_location.lat
routes.legs[0].start_location.lng
Upvotes: 0