2

I want to restrict map to specific distance as example 15 km from my current location to restrict user navigate to another locations.

I can calculate the distance between 2 points correctly based on the following function

public static double distFrom(double lat1, double lng1, double lat2, double lng2) {
    double earthRadius = 6371.0; // earth radius in km
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double sindLat = Math.sin(dLat / 2);
    double sindLng = Math.sin(dLng / 2);
    double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2)
            * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = earthRadius * c;

    return dist;
}

but cannot get possible latitude and longitude from my location in all sides based on specific distance because user can navigate in any side in map.

I tried this example but not give my accurate result.

Ahmed
  • 103
  • 2
  • 9
  • @pskink is it contain any solution to my problem ? I know it can get all coordinate between two points but can give me lat & lng for specific distance ? – Ahmed Dec 03 '17 at 14:23
  • @pskink, yeah i know the computeOffset return LatLng for specific distance but how to add heading this is my problem how to get accurate heading to return start and end LatLng for this distance – Ahmed Dec 03 '17 at 14:54

1 Answers1

0

Check this answer here: https://stackoverflow.com/a/7478827/1397821

Now put all angles 0-360 in the equations mentioned in the above answer to get all the Lat Longs.

Hope this helps

M. Usman Khan
  • 3,689
  • 1
  • 59
  • 69