标记拖动事件时获取 latlng 值的通用方法(Google 地图)

Generic way to get latlng value when marker dragged event (Google Map)

当标记拖动事件触发时,我正在使用这种技术来获取 latlng 的值。

 google.maps.event.addListener(marker, 'dragend', function (event) {

                mouseLocation = event.latLng;

                alert("Longitude = " + mouseLocation.K + " Latitude = " + mouseLocation.G)

});

但现在 mouseLocation.K 和 mouseLocation.G 显示为未定义。这将转换为 mouseLocation.H 和 mouseLocation.L。有没有通用的方法来获得这两个值,这样我以后就不需要更改我的代码了。

不要使用 Google 地图对象的未记录属性。只要做 mouseLocation.lat()mouseLocation.lng()

https://developers.google.com/maps/documentation/javascript/reference#LatLng

试试 event.latLng.lat() and event.latLng.lng()

给你:这个

mouseLocation = event.latLng;
alert("Longitude = " + mouseLocation.lng()+ " Latitude = " + mouseLocation.lat());