javascript - 谷歌地图 JavaScript API

标签 javascript jquery google-maps google-maps-api-3

我知道您可以在经/纬度坐标上放置标记,但我很难找到在特定街道地址上放置标记的位置/方式。谁能告诉我该怎么做?我正在使用 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/

相关文章:

javascript - 如何使用多个 ID 重构这种颜色变化

javascript - 在我认为应该报告真实的时候不报告,而是全部报告错误

javascript - 从外部类获取 CSS

google-maps - 将 LatLng 分离为字符串 Google map

javascript - babel-plugin-* 和 babel-preset-* 有什么区别

javascript - jquery将thead tr td的属性复制到tbody tr td

javascript - 如何通过 "radio"实现 "button"

javascript - jQuery .width() 在页面加载时关闭

javascript - 在 javascript 中带有标签的多段线

javascript - Mobile Safari 中的 Google Maps v3 InfoBox 事件传播