简体   繁体   English

类型错误:无法读取未定义的属性“PlacesService”

[英]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.

相关问题 未捕获到的TypeError:无法读取Google Map API中未定义的属性“ PlacesService” - Uncaught TypeError: Cannot read property 'PlacesService' of undefined in google map api 为什么此代码会抛出“google 未定义”错误以及“TypeError:无法读取初始化时未定义的属性“PlacesService” - 错误? - Why is this code throwing 'google not defined' error and also 'TypeError: Cannot read property 'PlacesService' of undefined at initialize' - error? TypeError:无法读取未定义的属性… - TypeError: Cannot read property … of undefined TypeError:无法读取未定义的属性 - TypeError: Cannot read property of undefined 类型错误:无法读取未定义的属性“then” - TypeError: Cannot read property 'then' of undefined 无法读取未定义的属性“ on”(TypeError) - Cannot read property 'on' of undefined (TypeError) TypeError:无法读取未定义#2的属性&#39;then&#39; - TypeError: Cannot read property 'then' of undefined #2 TypeError:无法读取未定义的属性“0” - TypeError: Cannot read property '0' of undefined TypeError无法读取未定义的属性 - TypeError Cannot read property of undefined 未捕获的TypeError:无法读取未定义的属性“未定义” - Uncaught TypeError: Cannot read property 'undefined' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM