Calculate nearest location Google Map Android Studio -


i know how find distance between 2 location on android studio google map how calculate distance nearest 1 compering 3 or 4 found location?

   public void ondirectionfindersuccess(list<route> routes) {     progressdialog.dismiss();     polylinepaths = new arraylist<>();     originmarkers = new arraylist<>();     destinationmarkers = new arraylist<>();      (route route : routes) {         mmap.movecamera(cameraupdatefactory.newlatlngzoom(route.startlocation, 16));         ((textview) findviewbyid(r.id.tvduration)).settext(route.duration.text);         ((textview) findviewbyid(r.id.tvdistance)).settext(route.distance.text);          originmarkers.add(mmap.addmarker(new markeroptions()                 .icon(bitmapdescriptorfactory.fromresource(r.drawable.start_blue))                 .title(route.startaddress)                 .position(route.startlocation)));         destinationmarkers.add(mmap.addmarker(new markeroptions()                 .icon(bitmapdescriptorfactory.fromresource(r.drawable.end_green))                 .title(route.endaddress)                 .position(route.endlocation)));          polylineoptions polylineoptions = new polylineoptions().                 geodesic(true).                 color(color.blue).                 width(10);          (int = 0; < route.points.size(); i++)             polylineoptions.add(route.points.get(i));          polylinepaths.add(mmap.addpolyline(polylineoptions));     } } 

if want calculate distance,you can calculate way

 private double caldistance(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);     } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo