1

我是 Google Maps API 的新手,下面的 Google Map 正在工作。但是,我很难理解如何设置地址。我有 2,000 个条目,每个条目都包含一个存储在数据库中的地址,如果有机会,我拥有“设置”描述页面的地图 onLoad 地址所需的所有数据。但是,我不知道该怎么做。我想知道是否有人可以向我展示一个设置地址、城市、州、邮编然后在地图上也有标记的基本示例。

另外,我很困惑,如果我将地址的所有组成部分分开,我就不需要进行地理编码,对吗?地理编码不是很容易从未解析的/长地址字符串创建地图并限制您可以请求地理编码的次数吗?换句话说,如果我将所有地址组件(例如 zip、城市、州、地址等)存储在数据库中,那么我不能在不受谷歌地图地理编码限制的情况下设置地址吗?

以下地址:

123 Flower Street, Miami, Florida 32826

我的JS到目前为止...

   function initialize() {
        var mapOptions = {
            center: new google.maps.LatLng(-34.397, 150.644),
            zoom: 8,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
    }
    google.maps.event.addDomListener(window, 'load', initialize);

我很感激任何建议!

提前谢谢了!

4

1 回答 1

4

您正在寻找地理编码:https ://developers.google.com/maps/documentation/geocoding/

在这里,您有代码查询谷歌您的地址位置,然后在收到的位置上指向一个标记:

  function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(-34.397, 150.644),
      zoom: 8,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map-canvas"),
        mapOptions);
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({ 'address': "123 Flower Street, Miami, Florida 32826" }, 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("Problem with geolocation");

      });
  }
  google.maps.event.addDomListener(window, 'load', initialize);
于 2013-07-08T17:48:31.470 回答