[英]TypeError: Cannot read property 'PlacesService' of undefined
My objective is to request a group of locations that fit my criteria using a "routeRequest" and save them.我的目标是使用“routeRequest”请求一组符合我的条件的位置并保存它们。 In order to to that, I was to use google Places to check the locations around the center of my map.
为此,我使用 Google Places 来检查地图中心周围的位置。
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);
}
}
}
The issue is, placesService doens't seem to recognize the map问题是,placesService 似乎无法识别地图
It looks like you are getting this error because you haven't loaded the places library .看起来您收到此错误是因为您尚未加载Places 库。 In
index.html
you have this Maps API script:在
index.html
有这个 Maps API 脚本:
<script async src="https://maps.googleapis.com/maps/api/js?key="></script>
Add the following:添加以下内容:
<script async src="https://maps.googleapis.com/maps/api/js?key=&libraries=places"></script>
Hope this helps!希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.