0

我想将坐标和缩放级别存储到文本框以进行位置标记但遇到困难。我正在一个房地产网站上工作,我必须分别找到每个属性,为此我存储纬度和经度并放大数据库。

<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false"></script>

<script>
var myCenter=new google.maps.LatLng(51.508742,-0.120850);

function initialize()
{
var mapProp = {
  center:myCenter,
  zoom:5,

  mapTypeId:google.maps.MapTypeId.ROADMAP
  };

var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);



var marker=new google.maps.Marker({
  position:myCenter,
  draggable:true,
  });

google.maps.event.addListener(marker, 'dragend', function(event) 
{
document.projects.latitude.value = myCenter.lat(); 
document.projects.longitude.value=myCenter.lng();
document.projects.zoom.value= getZoom();
});


marker.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
<div id="googleMap" style="width:500px;height:380px;"></div>

<form action="" method="post" name="projects">

<input name="latitude" type="text">
<input name="longitude" type="text">
<input name="zoom" type="text">

</form>
</body>
</html>
4

1 回答 1

1

如果您想检索标记的位置,您应该这样做:

google.maps.event.addListener(marker, 'dragend', function(event) {
    document.projects.latitude.value = marker.position.lat(); 
    document.projects.longitude.value = marker.position.lng();
    document.projects.zoom.value= map.getZoom();
});
于 2012-11-19T14:49:48.057 回答