How to get the lat & lng as separate variables from mapCenter
16,492
var NewMapCenter = map.getCenter();
will give you LatLng object, so you can call
var latitude = NewMapCenter.lat();
var longitude = NewMapCenter.lng();
Related videos on Youtube
Author by
Sebastian
Updated on June 04, 2022Comments
-
Sebastian almost 2 years
I have the map center, and comes as a Floating Point number.
How can I get it as 2 separated variables like this:
var lat = ... var lng = ...
I have the float:
var NewMapCenter = map.getCenter();
I tried to pass the float
toWords(x)
but didn't workI tried to subtract the
(,)
andsplit
it, but didn't workvar latlngStr = (StrNewMapCenter.substr(1, (StrNewMapCenter.length-1))).split(",",2); var NewMapCenter = parseFloat(latlngStr[0]);
I tried, this but comes as an event, but I need it without needing to click.
google.maps.event.addListener(map, 'click', function(event) { var myLatLng = event.latlng; var Newlat = position.coords.latitude; var Newlng = position.coords.longitude; }
Thanks Sebastian
-
nrabinowitz over 12 years@Sebastian - if this is the right answer, you can mark it as correct by clicking the checkbox to the left of it. That'll close the question and give some extra rep to the person answering.
-
Sebastian over 12 yearsThanks, I didn't know, I just did it ;o) @nrabinowitz