2012-01-09 194 views
2

我知道你可以在長/緯度座標上放置一個標記,但我很難找到你在哪裏/如何在特定街道地址上放置標記。誰能告訴我如何做到這一點?我正在使用API​​和JQuery的V3。谷歌地圖Javascript API

回答

2

權,基本上是通過對地理編碼調用查詢通過地址地圖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); 
    } 
     }); 
    } 
} 
0

@詹姆斯指出如何經營地址解析請求,但你可以採取一個jQuery插件,像landcarte的優勢使其更短,更清晰的那樣:

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