使用谷歌地图获取纬度和长度



我想使用谷歌地图拖动事件获取标记的纬度和经度。不是标记拖动事件。我需要将标记设置为固定(。

这是我的代码

function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
center: myLatlng,
zoom: 8
};
var map = new google.maps.Map(document.getElementById("sample"),
mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: ''
});
google.maps.event.addListener(map, 'center_changed', function() {
// 0.1 seconds after the center of the map has changed,
// set back the marker position.
//alert(center)
window.setTimeout(function() {
var center = map.getCenter();
marker.setPosition(center);
}, 100);
});
}
google.maps.event.addDomListener(window, 'load', initialize);

@JIJOMON K.A,请尝试使用以下解决方案,

function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
center: myLatlng,
zoom: 8
};
var map = new google.maps.Map(document.getElementById("googleMap"),
mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: ''
});
google.maps.event.addListener(map, 'center_changed', function() {
window.setTimeout(function() {
var center = map.getCenter();
console.log(marker.getPosition().lat());
console.log(marker.getPosition().lng());
}, 100);
});
}
google.maps.event.addDomListener(window, 'load', initialize);

相关内容

  • 没有找到相关文章

最新更新