latLng返回空对象-谷歌地图javascript API
我使用带有javaScript的google地图,我的代码是:latLng返回空对象-谷歌地图javascript API,javascript,google-maps,Javascript,Google Maps,我使用带有javaScript的google地图,我的代码是: <script type="text/javascript"> var map; function initialize() { var myLatlng = new google.maps.LatLng(-12.043333,-77.028333); var myOptions = { zoom: 17, center: myLatlng
<script type="text/javascript">
var map;
function initialize() {
var myLatlng = new google.maps.LatLng(-12.043333,-77.028333);
var myOptions = {
zoom: 17,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
map = new google.maps.Map(document.getElementById('map_canvas'),
myOptions);
google.maps.event.addListener(map, "mousedown", function (e) {
//lat and lng is available in e object
var latLng = e.latLng;
console.log(latLng);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>`
e.latLng的结果是一个空对象。
我试图单击事件,但结果为空。
我应该做什么或更改什么?您的代码工作正常: 点击地图,你们的坐标将进入警戒状态
请根据检查,地图类上没有“mousedown”事件。可能您想改为使用“单击”。您正在记录的对象是google.maps.LatLng对象。它有一个.lat、.lng和UrlValue方法,请尝试使用它们。。。它仍然不起作用:结果是:对象{lat:u.F/this.lat,lng:u.F/this.lng}我正在使用localhost