我希望当我点击地图时我可以获得Lat / Long并在alert()中显示 这是我的代码:
<!DOCTYPE html>
<html>
<body>
<div id="googleMap" style="width:100%;height:400px;"></div>
<script>
function myMap() {
var mapProp= {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBu-916DdpKAjTmJNIgngS6HL_kDIKU0aU&callback=myMap"></script>
</body>
</html>
我的代码很简单,我是从This link
获得的答案 0 :(得分:2)
类似的东西:
google.maps.event.addListener(map, 'click', function(event) {
// get a marker if you want
marker = new google.maps.Marker({position: event.latLng, map: map});
// alert out the lat/lng...
alert('Lat:' + event.latLng.lat() + ', Lng:' + event.latLng.lng());
});