【问题标题】:How to create two google maps如何创建两个谷歌地图
【发布时间】:2016-10-20 08:44:09
【问题描述】:

我想知道如何在两个公司的信息窗口中嵌入两个不同的谷歌地图。 this is sample one, i want two different maps 。 我想要两张不同的地图。 同一地图中不能有两个信息窗口。

谢谢。

【问题讨论】:

标签: javascript google-maps


【解决方案1】:

在你的 html 中放两个 div 而不是一个:

...
<div id="map1"></div>
<div id="map2"></div>
...

然后添加 javascript 代码来创建两个地图:

  function initMap(mapName, lat, lng, title, content) {
    var map = new google.maps.Map(document.getElementById(mapName), {
      zoom: 4,
      center: {lat: lat, lng: lng}
    });

    var infowindow = new google.maps.InfoWindow({
      content: content
    });

    var marker = new google.maps.Marker({
      position: coords,
      map: map,
      title: title
    });
    marker.addListener('click', function() {
      infowindow.open(map, marker);
    });
  }

var contentUrulu = '<div id="content">'+
            '<div id="siteNotice">'+
            '</div>'+
            '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
            '<div id="bodyContent">'+
            '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
            'sandstone rock formation in the southern part of the '+
            'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+
            'south west of the nearest large town, Alice Springs; 450&#160;km '+
            '(280&#160;mi) by road. Kata Tjuta and Uluru are the two major '+
            'features of the Uluru - Kata Tjuta National Park. Uluru is '+
            'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
            'Aboriginal people of the area. It has many springs, waterholes, '+
            'rock caves and ancient paintings. Uluru is listed as a World '+
            'Heritage Site.</p>'+
            '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
            'https://en.wikipedia.org/w/index.php?title=Uluru</a> '+
            '(last visited June 22, 2009).</p>'+
            '</div>'+
            '</div>';
var
    contentWhatever = '...';

  initMap('map1', -25.363, 131.044, 'Uluru (Ayers Rock)', contentUrulu);
  initMap('map2', 46.106,7.049, 'Whatever', contentWhatever);

【讨论】:

    猜你喜欢
    • 2016-11-27
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多