Thursday, May 17, 2007

String to a GLatLng() object

Now we have a handy undocumented method
.fromUrlValue();

It converts a coordinate pair string like "60.21, 24.95" to a GLatLng object:

var latLngString = "60.21, 24.95"
var point = GLatLng.fromUrlValue(latLngString);

Nice. The method performs split(",") and parseFloat() for you. It simplifies parsing of many file formats. Actually I am converting my Spreadsheets to have a 'latlng' column instead of 'lat' and 'lng' columns. It makes copy-paste-filling of the spreadsheet easier.

1 comment:

tipu said...

I've been looking all over for a solution to convert coordinates from type String to the proper google maps object. Thanks!