zoom over specific route google map

前端 未结 9 1084
感动是毒
感动是毒 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条回答
  • 2021-02-05 12:05

    you can do one thing, find out the distance between 2 latitude and longitude and make check over distance that you got.See,how it work . It's a trick it might useful for you.

    googleMap.moveCamera(CameraUpdateFactory.newLatLng(reachLocationLatLng));
    if (dist > 2 && dist <= 5) {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(13.0f));
    mapZoomLevel = 12;
    } else if (dist > 5 && dist <= 10) {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(12.0f));
    mapZoomLevel = 11;
    } else if (dist > 10 && dist <= 20) {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(11.0f));
    mapZoomLevel = 11;
    } else if (dist > 20 && dist <= 40) {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(10.0f));
    mapZoomLevel = 10;
    } else if (dist > 40 && dist < 100) {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(9.0f));
    mapZoomLevel = 9;
    } else if (dist > 100 && dist < 200) {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(8.0f));
    mapZoomLevel = 8;
    } else if (dist > 200 && dist < 400) {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(7.0f));
    mapZoomLevel = 7;
    } else if (dist > 400 && dist < 700) {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(6.0f));
    mapZoomLevel = 7;
    } else if (dist > 700 && dist < 1000) {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(5.0f));
    mapZoomLevel = 6;
    } else if (dist > 1000) {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(4.0f));
    mapZoomLevel = 5;
    } else {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(14.0f));
    mapZoomLevel = 14;
    }
    

    Thanks hope this will help you.

    0 讨论(0)
  • 2021-02-05 12:07
     googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(endPoint,zoomLevel));
    

    Try it if it helps you

    0 讨论(0)
  • 2021-02-05 12:16

    This is very late to answer try with this shortest way

    First of All get your current location latlongs then your write code for your destination lat longs then calculate distance between your current location and destination location with this code

    private double distance(double lat1, double lon1, double lat2, double lon2) {
      double theta = lon1 - lon2;
      double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
      dist = Math.acos(dist);
      dist = rad2deg(dist);
      dist = dist * 60 * 1.1515;
       return (dist);
    }
    private double deg2rad(double deg) {
      return (deg * Math.PI / 180.0);
    }
    private double rad2deg(double rad) {
      return (rad * 180.0 / Math.PI);
    }
    
    • you can never get same lat longs data because of GPS count 95 meters from your current location to display current location pin or lat long data. either you are same location you can never find exact lat long data this must be differ in points so thats by you need to get distance your current location to your fix lat long data points.

    • when ever you find "distance" from your destination points to current lat long then fire this code to animate camera and zoom.

      map.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx),21));
      
    0 讨论(0)
提交回复
热议问题