相机移动时,Google Maps更新url LatLngBounds并缩放

时间:2019-07-15 18:32:06

标签: google-maps ionic4

我目前正在研究离子本机Google地图和建筑物的天气图。基本上,我想在相机移动时获取LatLngBounds和缩放级别,然后将这些数据传递给url甚至在地图上显示数据。

例如,每次移动地图和缩放级别时,URL都会动态更新。

http://www.xxxxxxxx.net/map#lat=-25.87899&lng=-42.45117&zoom=4

我的代码:

     getData(){

         ////Here should pass LatLngBounds in url ////

        this.http.get('xxxxxxx/MetarJSON.php?bbox='','','',''' ,{},{}).then(data=>{

        let DataJson = JSON.parse(data.data)

        for (let datas of DataJson['features']) {

          this.points.push({ lng: datas.geometry.coordinates[0], lat: datas.geometry.coordinates[1] });

        }

        for (let i = 0; i <  DataJson.features.length; i++) {

          let coords = DataJson.features[i].geometry.coordinates;
          this.latLng = new LatLng(coords[1], coords[0]);
          this.icoa = DataJson.features[i].properties.id
          this.rawOb = DataJson.features[i].properties.rawOb
          let fltcat = DataJson.features[i].properties.fltcat


          let marker: Marker = this.map.addMarkerSync({
            position: this.latLng,
            title:fltcat,
            icon: icons
          })



        }


        })

      }

      loadMap() {

        let mapOptions: GoogleMapOptions = {
          camera: {
             target: {
               lat: 33.263,
               lng: 44.232
             },
             zoom: 6,
           }
        };

        this.map = GoogleMaps.create('map_canvas', mapOptions);


  ////   Here l get LatLngBounds but when l move map the lat and lng aren't update

     let chec1=  this.map.getVisibleRegion().farLeft.lat
     let chec2=  this.map.getVisibleRegion().farLeft.lng
      console.log(chec1,chec2)
      }

Ionic Google map native plugin Doc

1 个答案:

答案 0 :(得分:0)

我在移动地图以更新LatLngBounds时找到了解决方案。使用过的GoogleMapsEvent常量

取决于doc,他工作正常

   this.map.on(GoogleMapsEvent.CAMERA_MOVE).subscribe(()=>{

          let left=  this.map.getVisibleRegion().northeast.lat
          let leftbottom=  this.map.getVisibleRegion().northeast.lng
          let right=  this.map.getVisibleRegion().southwest.lat
          let rightbottom=  this.map.getVisibleRegion().southwest.lng
           console.log(left,leftbottom , right ,rightbottom )
        })