编程语言
首页 > 编程语言> > javascript-MapsApi-Google Maps Place服务出现奇怪的错误

javascript-MapsApi-Google Maps Place服务出现奇怪的错误

作者:互联网

Google Maps Place服务无法正常工作并给出下一个错误

Uncaught Error: Property radius is invalid. A possible cause is that the value conflicts with other properties.

var service = new google.maps.places.PlacesService(map);
var request = {
    location: centerLatLong,
    rankBy: google.maps.places.RankBy.DISTANCE,
    radius: 500
}; 
service.nearbySearch(request, function(results, status){
    if (status == google.maps.places.PlacesServiceStatus.OK){
        console.log(results)
    }
});

解决方法:

使用rankBy:distance时,不支持radius-property.

Javascript-API的文档似乎不完整,因为它不包含使用rankBy:distance时不允许半径属性的信息,但places-Webservice的文档包含以下信息:

radius — Defines the distance (in meters) within which to return place
results. The maximum allowed radius is 50 000 meters. Note that radius
must not be included if rankby=distance
(described under Optional
parameters below) is specified.

https://developers.google.com/places/webservice/search#PlaceSearchRequests

解决方案:删除半径属性

标签:google-places-api,google-maps,google-maps-api-3,javascript
来源: https://codeday.me/bug/20191028/1949699.html