谷歌地图定制的针脚

时间:2016-04-17 12:03:15

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

我已经用Google制作了一张地图: Google API

但是我想再添加8个引脚,这应该说明我在世界上的地方。但我不知道我是否能从那段代码那里做到这一点?

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Simple markers</title>
    <style>
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map {
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>

      function initMap() {
        var place_1 = {lat: -25.363, lng: 131.044};
        var place_2 = {lat: 55.971232, lng: 9.854725};

        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 4,
          center: myLatLng
        });

        var marker = new google.maps.Marker({
          position: myLatLng,
          map: map,
          title: 'Hello World!'
        });
      }
    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=xxxxxx&callback=initMap">
    </script>
  </body>
</html>

1 个答案:

答案 0 :(得分:1)

您可以根据需要使用任意数量的标记:

function initMap() {
    //this is different:
    var places = new Array();
    places.push({lat: -25.363, lng: 131.044});
    places.push({lat: 55.971232, lng: 9.854725});
    //push all of remaining places

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 4,
      center: myLatLng
    });

    //and this is different:
    var markers = new Array();
    for(var i = 0; i < places.length; i++){
      markers.push(new google.maps.Marker({
        position: new google.maps.LatLng(places[i].lat, places[i].lng),
        map: map,
        title: 'Hello World!'
      }));
    }
  }