zoom over specific route google map

前端 未结 9 1177
感动是毒
感动是毒 2021-02-05 11:23

I have a list of random latitude and longitude points and I am drawing a route between them. My question is how to bound this route within google map I made below utili

9条回答
  •  萌比男神i
    2021-02-05 11:56

    Probably This would be most simple solution for above mentioned problem, It worked for me very well.

    Add all the waypoints to the target under GoogleMapOptions:camera, then it will automatically set the zoom and center the map with respect to Polyline( given Route).

    loadMap() {
    
    let mapOptions: GoogleMapOptions = {
      camera: {
        target: this.wayPoints,
        zoom: 25,
        tilt: 30
      }
    };
    
    this.map = GoogleMaps.create('map_canvas', mapOptions);
    this.map.one(GoogleMapsEvent.MAP_READY)
      .then(() => {
        console.log('Map is ready!');
    
    
       this.map.addPolyline({
          points:this.wayPoints,
          color:'#586bff',
          width: 8,
          geodesic:true,
        });
    });
    }
    

    The waypoints( this.wayPoints ) should be in this format:

    [{lat: 52.33806, lng: 8.61179},
    {lat: 52.33812, lng: 8.61185},
    {lat: 52.33812, lng: 8.61186},
    {lat: 52.33812, lng: 8.61188}]
    

提交回复
热议问题