admin管理员组文章数量:1197752
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 work
I tried to subtract the (,)
and split
it, but didn't work
var 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
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 work
I tried to subtract the (,)
and split
it, but didn't work
var 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
Share Improve this question edited Mar 19, 2013 at 16:52 Mathew Thompson 56.4k15 gold badges129 silver badges150 bronze badges asked Jan 20, 2012 at 14:30 SebastianSebastian 4852 gold badges8 silver badges22 bronze badges1 Answer
Reset to default 25var NewMapCenter = map.getCenter();
will give you LatLng object, so you can call
var latitude = NewMapCenter.lat();
var longitude = NewMapCenter.lng();
本文标签: javascriptHow to get the lat amp lng as separate variables from mapCenterStack Overflow
版权声明:本文标题:javascript - How to get the lat & lng as separate variables from mapCenter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738562195a2099451.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论