0

我正在玩 Firefox 插件 Ubiquity。我正在尝试在预览页面上放置自定义谷歌地图。该页面应包含以下内容:

<html>
<head>
  <title>Google Maps Multiple Markers</title>
  <script src="https://maps.googleapis.com/maps/api/js?key=MY_KEY" type="text/javascript"></script>
</head>
<body>
<div id="map" style="height: 400px; width: 500px;"></div>
<script type="text/javascript">
    var locations = ['Bondi Beach', 'Coogee Beach', 'Cronulla Beach', 'Manly Beach', 'Maroubra Beach'];

    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 marker, i;
    var geocoder = new google.maps.Geocoder();

    for (i = 0; i < locations.length; i++) {
        console.log("coding " + locations[i]);
        geocoder.geocode({'address': locations[i].toLowerCase()}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location
                });
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
    }
  </script>
</body>
</html>

但是locations变量应该由输入设置。这个想法是让用户映射多个位置(这个功能曾经存在,我正在尝试重新制作它)。我试过简单地设置pblock.innerHTML它,但是虽然它似乎得到了输入,但什么也没有出现。我已经尝试对默认map命令的功能进行逆向工程,但我不明白它是如何工作的。

4

1 回答 1

0

我通过复制包含 map 命令的整个文件并剪切所有部分来解决这个问题,直到只剩下我需要的部分。我仍然不确定为什么我的旧解决方案不起作用..

于 2016-07-12T08:27:06.490 回答