简体   繁体   English

Google地图标记位置不正确

[英]Google map marker not in correct position

Here is the code that I written: 这是我编写的代码:

<!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>
  • When I run the above code, all marker is not in correct position as shown as image below: 当我运行上面的代码时,所有标记都不在正确的位置,如下图所示: 在此处输入图片说明

  • Am I writing the wrong code? 我写错了代码吗?

Your values are wrong see the map for an example 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 您的值有误,请参见地图示例https://www.google.com/maps/place/51%C2%B030'17.0%22N+0%C2%B007'18.1%22W/@51.504728,-0.1216795, 17z /数据=!3m1!4b1!4m2!3m1!1s0x0:0x0

I don't know what you are trying to point at but it is pointing exactly where you are asking it too. 我不知道您要指出的是什么,但这也正是您要问的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM