簡體   English   中英

谷歌地圖上的標記標題

[英]Marker titles on google map

我正在嘗試從地址開始在地圖上放置標記。 有用。 雖然每個標記都有一個標題,並且應該是實際地址,但所有標記都具有相同的標題,我該如何解決?

        <script src="https://maps.googleapis.com/maps/api/js?key=MYAPIKEY
    "></script>
        <script>
          // locations 
            var addo;
            var indirizzi = [
            ['Via'],
            ['Via Padova 175 - 20127 Milano (MI)'],
            ['via della Chiesa Rossa n. 69 - 20142 Milano (MI)'],
            ['Via Lucilio Gaio n. 5 - 20151 Milano (MI)'],
            ['VIA EMANUELE ODAZIO 6 - 20147 Milano (MI)'],
            ['VIA PRIVATA GIOVANNI BATTISTA PRANDINA 11 - 20128 Milano (MI)'],
            ['Via della Capinera n. 5-6 Milano (MI)'],
            ['Via Privata Uberto DellOrto n. 11 - 20161 Milano (MI)'],
            ['Via Michele Lessona n. 5 - 20157 Milano (MI)'],
            ['via Fulvio Testi n. 58 Milano (MI)'],
            ['via Giulio e Corrado Venini n. 90 Milano (MI)'],
            ];

  function initialize() {

    var geo = new google.maps.Geocoder;
    var bangalore = { lat: 45.46, lng: 9.19 };

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


     for (i = 0; i < indirizzi.length; i++) {
     addo=indirizzi[i][0];

     geo.geocode({'address':indirizzi[i][0]},function(results, status){
       addMarker(results[0].geometry.location, map, addo);
     })
    }
  }
  // Adds a marker to the map.
  function addMarker(location, map, titolo) {

    var marker = new google.maps.Marker({        
      position: location,
      title: titolo,
      map: map
    });
  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>

請注意,我已經刪除了我的個人API密鑰。

試試這個也許對您有幫助。

  var locations = [
          ['Bondi Beach', -33.890542, 151.274856, 4],
          ['Coogee Beach', -33.923036, 151.259052, 5],
          ['Cronulla Beach', -34.028249, 151.157507, 3],
          ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
          ['Maroubra Beach', -33.950198, 151.259302, 1]
        ];

        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 10,
          center: new google.maps.LatLng(-33.92, 151.25),
          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));
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM