我正在尝试在Google地图的建筑物/建筑物上添加标记,为此,我正在使用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给出的答案
不知道以前是否有人遇到过此问题。也许还有另一种方法可以解决这个问题。
更新
如果有人偶然发现了这个问题,可以使用Places Library在Google Maps上搜索商家/地点。这将返回带有公司地址,位置,名称等的对象。
希望这可以帮助某人:)
最佳答案
我对Geocode API的功能有些困惑。再次阅读requests的API。
必需的参数是address
或latlng
或components
和sensor
。
可选参数是bounds
,language
,region
和components
。Premise
是returned JSON data的属性之一。这意味着您不能将其用作搜索参数,这就是API抱怨的原因。
您链接到的那个问题的答案是错误的。
希望这会有所帮助。