how to parse out lat/lng from geocoder results question

1,292 views
Skip to first unread message

DMacLeod

unread,
Jul 23, 2010, 10:30:35 AM7/23/10
to Google Maps JavaScript API v3
I'm receiving lat/lon from geocoder via var coords =
results[0].geometry.location; (example: (27.345, -80.678)
I'm trying to parse out the lat and lon by doing a javascript slice
function. However this does not work. So, I figured I could do
something like: var lat = results[0].geometry.location.lat; However,
this returns: lat function(){return this[a]}. How can I pull the lat
and lng from the results?

thanks
Dan

geoco...@gmail.com

unread,
Jul 24, 2010, 3:03:30 AM7/24/10
to Google Maps JavaScript API v3
Did you try:
var lat = results[0].geometry.location.lat();
per the documentation:
location: LatLng

http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLng

LatLng has a method .lat(), not a property .lat

-- Larry

>
> thanks
> Dan

jquertil

unread,
Jun 19, 2012, 7:23:34 PM6/19/12
to google-map...@googlegroups.com
1. if you're using the geocoder outside of a google map you're in violation of their terms of service.
2. if you're doing it inside a google map, you don't need to parse anything. The location is an object and you can set the map center for example, like this:

map.setCenter(results[0].geometry.location);


This is all in the official documentation about geocoding, btw.

Shreerang Patwardhan

unread,
Jun 20, 2012, 9:42:10 AM6/20/12
to google-map...@googlegroups.com
Try looking at these examples.

1. http://shreerangpatwardhan.blogspot.sg/2010/12/retriving-co-ordinates.html

2. http://shreerangpatwardhan.blogspot.sg/2010/11/playing-with-markers-and-info-window.html

Regards.
--
Shreerang Patwardhan
Software Engineer
Website Spatial Unlimited
Email  patwardhan...@gmail.com


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/XvjKCRY8ocsJ.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply all
Reply to author
Forward
0 new messages