use*_*083 2 javascript google-maps google-places-api vue.js
我的目标是使用“routeRequest”请求一组符合我的标准的位置并保存它们。为此,我使用谷歌地点来检查地图中心周围的位置。
let map = new google.maps.Map(document.querySelector("#myMap"), {
center: { lat: 41.148481, lng: -8.606893 },
zoom: 15
});
let service = new google.maps.places.PlacesService(map);
service.nearbySearch(routeRequest, callback);
let routeRequest = {
location: map.center,
radius: '1000',
type: [this.typeRoute]
};
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (const result of results) {
this.listLocations.push(result);
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,placesService 似乎无法识别地图
看来您收到此错误是因为您尚未加载地方库。您有index.html这个 Maps API 脚本:
<script async src="https://maps.googleapis.com/maps/api/js?key="></script>
Run Code Online (Sandbox Code Playgroud)
添加以下内容:
<script async src="https://maps.googleapis.com/maps/api/js?key=&libraries=places"></script>
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!