I have a Geopoint that is the current position of the user. I know its latitude and longitude. I would like to get a square perimeter 50km around the user position so I need to know what are the min & max latitude and the min&max longitude around that given poin, in java. May someone helps me out with that ? Thanks in advance ?
Asked
Active
Viewed 1,851 times
1 Answers
3
Just found out the solution. If you have a given point P(lat, long). If you need to get 50 km around square perimeter for example, you need to take in consideration earth radius. Below how to do it:
double R = 6371; // earth radius in km
double radius = 50; // km
double latMin = lon - Math.toDegrees(radius/R/Math.cos(Math.toRadians(lat)));
double latMax = lon + Math.toDegrees(radius/R/Math.cos(Math.toRadians(lat)));
double longMax = lat + Math.toDegrees(radius/R);
double longMin = lat - Math.toDegrees(radius/R);
The real answer is here: credit to the real answerer

Community
- 1
- 1

Hubert Solecki
- 2,611
- 5
- 31
- 63
-
For a more generic solution you could use the `SphericalUtil.computeOffset()` method (http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/SphericalUtil.html#computeOffset-LatLng-double-double-) from the Google Maps Android API Utility Library (https://developers.google.com/maps/documentation/android-api/utility/). You can take a look at the code on GitHub: https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/SphericalUtil.java – antonio Feb 05 '16 at 16:56