谷歌地图Javascript API

谷歌地图Javascript API

问题描述:

我知道你可以在长/纬度坐标上放置一个标记,但我很难找到你在哪里/如何在特定街道地址上放置标记。谁能告诉我如何做到这一点?我正在使用API​​和JQuery的V3。谷歌地图Javascript API

权,基本上是通过对地理编码调用查询通过地址地图API。它应该返回给你一个LAT/LNG,然后你可以使用它来创建一个标记。

function mygeocoder(addr){ 
    var geocoder = new google.maps.Geocoder(); 

    if (geocoder) { 
     geocoder.geocode({ 'address': addr }, function (results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      console.log("LAT: ", results[0].geometry.location.lat()); 
      console.log("LNG: ", results[0].geometry.location.lng()); 
     } 
    else { 
     console.log("Geocoding failed: " + status); 
    } 
     }); 
    } 
} 

您将需要运行地理编码查询。

查看这个来源的详细信息:http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-simple.html

@詹姆斯指出如何经营地址解析请求,但你可以采取一个jQuery插件,像landcarte的优势使其更短,更清晰的那样:

var map = $("#map").geoMap(); 
map.search("Copenhagen", function(data) { 
    if (data.location) map.add("marker", data.location); 
});