我知道您可以在经/纬度坐标上放置标记,但我很难找到在特定街道地址上放置标记的位置/方式。谁能告诉我该怎么做?我正在使用 API 的 V3 和 JQuery。
最佳答案
对,基本上是通过调用 Geocoder 按地址查询 map 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);
}
});
}
}
关于javascript - 谷歌地图 JavaScript API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8793033/