首页 > 解决方案 > 离子原生谷歌地图 getVisibleRegion()

问题描述

我在使用Ionic Native 和 Google Maps时遇到问题。我正在使用map.getVisibleRegion()获取屏幕四个角的纬度。我的想法是仅加载该区域内的点,但是,在使用记录的代码后,我得到:

错误错误:未捕获(在承诺中):TypeError:无法读取 null 的属性“northeast”类型错误:无法读取 null 的属性“northeast”

this.map.getMyLocation()
      .then(
        (location: MyLocation) => {
          this.map.animateCamera({
            target: location.latLng,
            zoom: 17,
            tilt: 0,
            bearing: 150
          });
          // Getting the visible region of the map
          const visibleRegion = this.map.getVisibleRegion();
          this.map.addPolygonSync({
            'points': [
              visibleRegion.northeast,
              {lat: visibleRegion.northeast.lat, lng: visibleRegion.southwest.lng},
              visibleRegion.southwest,
              {lat: visibleRegion.southwest.lat, lng: visibleRegion.northeast.lng}
            ],
            'strokeColor' : 'blue',
            'strokeWidth': 2,
            'fillColor': 'rgba(255,0,0,.5)'
          });
        },
        this.loading.dismiss()
      );

任何人都可以发光吗?

标签: google-mapsionic-frameworkionic4ionic-native

解决方案


发现问题。需要订阅GoogleMapsEvent.MAP_READY.


推荐阅读