Google地图标记位置不正确

时间:2015-07-29 03:40:43

标签: javascript google-maps google-maps-api-3 google-maps-markers

这是我写的代码:

<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script>
var myCenter = new google.maps.LatLng(51.508742, -0.120850);

var neighborhoods = [
   new google.maps.LatLng(51.504728,-0.1216795),
   new google.maps.LatLng(51.5031154,-0.1207032),
   new google.maps.LatLng(51.5018457,-0.1225088),
   new google.maps.LatLng(51.503773,-0.1224413)
];

var markers = [];
var map;

function initialize() 
{
   var mapProp = 
   {
      center: myCenter,
      zoom: 16,
      mapTypeId : google.maps.MapTypeId.ROADMAP 
   };

   map = new google.maps.Map(document.getElementById('googleMap'), mapProp);
}

function drop() 
{
   clearMarkers();

   for (var i = 0; i < neighborhoods.length; i++) 
   {
       addMarkerWithTimeout(neighborhoods[i], i * 200);
   }
}

function clearMarkers() 
{
   for (var i = 0; i < markers.length; i++) 
   {
       markers[i].setMap(null);
   }

   markers = [];
}

function addMarkerWithTimeout(position, timeout) 
{
   window.setTimeout(function() 
   {
       markers.push(new google.maps.Marker
       ({
           position: position,
           map: map,
           animation: google.maps.Animation.DROP
       }));
   }, timeout);
}

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

<body>
<div id="panel">
   <button id="drop" onclick="drop()">Drop Markers</button>
</div>
<div id="googleMap" style="width:800px;height:600px;"></div>
</body>
</html>
  • 当我运行上面的代码时,所有标记位置都不正确,如下图所示: enter image description here

  • 我写错了代码吗?

1 个答案:

答案 0 :(得分:1)

您的值有误,请参阅地图以获取示例https://www.google.com/maps/place/51%C2%B030'17.0%22N+0%C2%B007'18.1%22W/@51.504728,-0.1216795,17z/data=!3m1!4b1!4m2!3m1!1s0x0:0x0

我不知道你想要指出的是什么,但它正指向你正在问的地方。