How to get lat & lng as separate variables from mapCenter

I have a map center and a floating point number.

How can I get this as two separated variables, such as:

var lat = ... var lng = ... 

I have a float:

 var NewMapCenter = map.getCenter(); 

I tried passing float toWords(x) but it didn't work

I tried to subtract (,) and split it, but didn't work

 var latlngStr = (StrNewMapCenter.substr(1, (StrNewMapCenter.length-1))).split(",",2); var NewMapCenter = parseFloat(latlngStr[0]); 

I tried, but this event is like an event, but I need it without the need for a 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

+6
source share
1 answer
 var NewMapCenter = map.getCenter(); 

will provide you with a LatLng object, so you can call

 var latitude = NewMapCenter.lat(); var longitude = NewMapCenter.lng(); 
+22
source

Source: https://habr.com/ru/post/906484/


All Articles