首页 > 解决方案 > 离子原生谷歌地图如何显示中心点和非常标记

问题描述

嘿伙计们,我正在使用 Ionic Native Google Maps 插件,我正在尝试在屏幕上显示所有点以及用户位置,我可以这样做,没问题,问题是我需要用户的位置以地图为中心并显示他周围的所有点。

我一直在尝试使用 put my all points into anew LatLngBounds并使用该方法设置每个点,.extend()但它不起作用。

请帮忙

async expandRadius() {
    const query = await this.queryPlaces(10);
    get(query).then(nearByPlaces => {
      const foundPlaces = [];
        nearByPlaces.forEach( el => {
          const placesData = {
            distance: Math.floor(this.geo.point(this.centerPoint.latitude, this.centerPoint.longitude)
              .distance(el.geolocation.geopoint.latitude, el.geolocation.geopoint.longitude)),
              ...el
          };
          foundPlaces.push(placesData);
          // THE CENTER ISSUE STARTS HERE //
          const tmp = new LatLng(el.geolocation.geopoint.latitude, el.geolocation.geopoint.longitude);
          this.bounds.extend(tmp);
          this.map.addMarkerSync({
            position: {
              lat: tmp.lat,
              lng: tmp.lng
            },
            icon: {
              url: 'www/assets/icon/pin.png',
              size: {width: 23, height: 33},
            }
          });
        });
        this.map.moveCamera({
          target: this.bounds.getCenter(),
          tilt: 0,
        });
    })
    .catch()
    .finally( async () => await this.loading.dismiss() );
  }

标签: google-mapsionic-frameworkionic4ionic-native

解决方案


推荐阅读