我正在尝试在Google Maps上的建筑物/前提上添加标记,以此为此,我正在使用地理编码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
属性请求建筑物/前提,但是当使用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
});
}
});
我遵循了这个问题的答案
不确定以前是否有人遇到过这个问题。也许还有另一种解决这个问题的方法。
update
以防有人偶然发现这个问题,要在Google地图上搜索业务/地点,您可以使用"位置"库。这将返回具有业务地址,位置,名称等的对象
希望这对某人有帮助:)
i这里对地理API的作用有些混乱。再次阅读请求的API 。
所需的参数是address
或latlng
或components
,以及sensor
。
可选参数为bounds
,language
,region
和components
。
Premise
是返回的JSON数据的属性之一。这意味着您不能将其用作搜索参数,这就是API抱怨的原因。
您链接到的问题的答案是错误。
希望这很有帮助。