【问题标题】:flag/mark locations in google map with location name用位置名称在谷歌地图中标记/标记位置
【发布时间】:2011-04-27 13:25:30
【问题描述】:

是否可以用位置名称动态标记谷歌地图中的位置。 客户将通过 rss 提要向我们提供位置名称。我们将使用 php 脚本抓取该位置(不用担心),然后想在谷歌地图中标记它们。

如果我们得到地址:Weston Town Recreation Department 20 Alphabet Ln, Weston, MA (781) 那么我们必须在谷歌地图上标记它

我不太了解如何发布此内容或标记此内容并在网页中动态显示,因为我是这个谷歌地图的新手

请在这个问题上指导我..

我还想在将鼠标悬停在谷歌地图中的标记上时弹出的弹出窗口中添加一些细节 - 请也为此提出解决方案

【问题讨论】:

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


    【解决方案1】:

    您需要Geocode 您的地址,然后使用results[idx].geometry.location 设置标记。 (谷歌地图地理编码页面有 an example 让你开始。)


    此处添加了 Google 代码,以防它发生更改/不复存在。

    var geocoder, map;
    function initialize() {
      geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(-34.397, 150.644);
      var myOptions = {
        zoom: 8,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    }
    
    function codeAddress() {
      var address = document.getElementById("address").value;
      geocoder.geocode( { 'address': address}, 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);
        }
      });
    }
    
    <body onload="initialize()">
     <div id="map_canvas" style="width: 320px; height: 480px;"></div>
      <div>
        <input id="address" type="textbox" value="Sydney, NSW">
        <input type="button" value="Encode" onclick="codeAddress()">
      </div>
    </body>
    

    【讨论】:

    • 地理编码文档已移动 here 和示例 there
    猜你喜欢
    • 2013-12-08
    • 1970-01-01
    • 2014-03-22
    • 2017-08-08
    • 1970-01-01
    • 2011-08-29
    • 2016-03-07
    • 2018-09-17
    • 2019-09-23
    相关资源
    最近更新 更多