首页 > 解决方案 > 标记未显示在正确位置

问题描述

我只是想在地图上显示多个标记。它可以工作,但标记不在正确的位置。为了在正确的位置显示标记,我必须指定什么。下面是我的代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <style>
            body {
    padding:0px;
    margin:0px;

            }
#map {
    display: table;
    width: 100%;
    height: 600px;
}            
        </style>

        <script src="https://maps.google.com/maps/api/js"></script>
    </head>
    <body>
        <div id="map"></div>
        

        <script>
var locations = [
      ['Elite Tuning', 53.214032, -2.551536, 3],
      ['North Wales Carbon', 53.294184, -3.579918, 2],
      ['os-Carz', 52.6629864, 1.1101281, 1]
    ];

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 8,
      center: new google.maps.LatLng(52.7646718, -1.2562978),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }
    </script>
    </body>
</html>

任何帮助表示赞赏。:)

提前致谢。

标签: mapsmarkers

解决方案


推荐阅读