Is it possible to convert a "LatLng obj" to Lat/Lon coordinates?

1,440 views
Skip to first unread message

WebbWebs

unread,
Mar 2, 2011, 6:06:53 PM3/2/11
to google-map...@googlegroups.com
Although I've been writing code for more years than I care to admit, I am a virtual newbie to Google's Mapping API. I'm currently developing an iPhone/iPad application that uses a Google map to select the location of their birthplace. On initialization, a world map is presented along with a text box for input of city, state, country, etc... whatever is needed to identify the location. This data then uses the JavaScript API v3 to convert the data into map coordinates zooming the map to appropriately identify the results.

So far, so good. The LatLng object works great for displaying the map, etc. Once the map is presented, however, I then need the actual latitude and longitude values for the application itself. It took me considerable time dealing with JS errors, before I realized that LatLng is NOT actually a string, but an object. (Yeah... I know... I should have read closer.) I have done considerable searching, but can find no solution for converting the "object" into a "string", so I can use the values in my application. While the LatLng object works quite well for Google's own maps, it certainly diminishes it's usefulness for anything else.

I can't imagine that I'm the only one facing this dilemma, but I neither can I find a published solution. Any assistance would be greatly appreciated.

Thanks,

Jack

Michael Geary

unread,
Mar 2, 2011, 6:27:52 PM3/2/11
to google-map...@googlegroups.com, WebbWebs
Generally, every object you work with in the Maps API is an actual JavaScript object, not just a string. Most of these objects have methods you can call to get information out of them.

Here's the LatLong doc:


See the table of Methods? That's what you're looking for. If you have a LatLng in a variable called latlng, then you can use latlng.lat() or latlng.lng() to get the individual numbers.

-Mike

--
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 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.

WebbWebs

unread,
Mar 2, 2011, 8:00:56 PM3/2/11
to google-map...@googlegroups.com, WebbWebs
Thank you, Mike.

I had tried latlng.lat() and latlng.lng() even before seeing the table of Methods you indicated. I had also tried results[0].geometry.location.lat and results[0].geometry.location.lng without success.

I've been working with navigational charts for many years and I'm one a very small list of NOAA authorized distributors for their charts. I'm not used to referring to "longitude" as "lng", but as "lon". My best guess is that I was probably using .lon() rather than .lng() out of habit. Who knows how long I'd have been playing around with this before I figured out the problem. Thanks for saving me a great deal of lost time and effort!

Jack

Reply all
Reply to author
Forward
0 new messages