首页 文章

谷歌 Map 地理编码:未知的 property 前提

提问于
浏览
1

我'm trying to add a marker on a building/premise on google maps, to do this I' m使用Geocoding API . 我通过请求地址测试了它,它完美地工作 .

var address = "...";
var geocoder = new google.maps.Geocoder();
geocoder.geocode( {'address': address }, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    var location_marker = new google.maps.Marker({
      map: map,
      position: results[0].geometry.location
    });
  }
});

根据地理编码API,您可以使用 premise 属性请求building/premise,但在使用 premise 时,我收到了一个JavaScript错误 Uncaught InvalidValueError: unknown property premise .

这就是我要求 premise 属性的方式:

var premise = "...";
var geocoder = new google.maps.Geocoder();
geocoder.geocode( {'premise': premise }, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    var location_marker = new google.maps.Marker({
      map: map,
      position: results[0].geometry.location
    });
  }
});

我按照给出的答案question

不确定是否有人之前有这个问题 . 也许还有另一种解决方法 .

UPDATE

如果有人偶然发现此问题,要搜索Google Map 上的商家/地点,您可以使用Places Library . 这将返回具有业务地址,位置,名称等的对象 .

希望这有助于某人:)

1 回答

  • 2

    关于Geocode API的作用,我对此感到困惑 . 再次阅读requests的API .

    必需参数是 addresslatlngcomponentssensor .

    可选参数是 boundslanguageregioncomponents .

    Premisereturned JSON data的属性之一 . 这意味着您不能将其用作搜索参数,这就是API抱怨的原因 .

    您链接的那个问题的答案是错误的 .

    希望这是有帮助的 .

相关问题