【问题标题】:Place Markers from Name, Address and Post Code来自姓名、地址和邮政编码的位置标记
【发布时间】:2013-03-20 04:39:50
【问题描述】:

在我的域模型中,对于有问题的实体,我有:

  • 地点名称(例如 Waterstones Wakefield)
  • 街道地址(例如 61-62 Bishopgate Walk)
  • 以及邮政编码(例如 WF1 1YB)

从以上三条信息中,我怎样才能得到一个放置在地图上的标记?我正在使用 Google Maps API 3。

谢谢

【问题讨论】:

  • 详细博客:goo.gl/d8w1J0
  • @SureshKamrushi 你称它为“详细博客”,但它只是一个代码 sn-p,根本没有解释它是如何工作的。

标签: google-maps-api-3 google-maps-markers street-address


【解决方案1】:

试试这个例子:

HERE THE ORIGINAL

HTML

      <body onload="initialize()">
        <div>
          <input id="address" type="text" value="Sydney, NSW">
          <input type="button" value="Geocode" onclick="codeAddress()">
        </div>
        <div id="map-canvas" style="height:90%;top:30px"></div>
      </body>

JS

 <script>
  var geocoder;
  var map;
  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var mapOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  }

  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);
      }
    });
  }
</script>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多