I need help with my code. I want to obtain the max latitude and the max longitude (in degrees) given a radius in meters and the actual position in latitude and longitude (in degrees). Can someone help me?
Thanks!!
First, every degree of latitude contains appx 111.1 km
, so it's easy to recalculate linear delta to latitude delta.
Second, linear appearance of 1 longitude degree is different and depends on latitude: small close to poles, large close to equator. Approximate equation is the following:
kmInLongitudeDegree = 111.320 * Math.cos( latitude / 180.0 * Math.PI)
Combining this, it's easy to get deltas of latitude and longitude that will cover your circle:
deltaLat = radiusInKm / 111.1;
deltaLong = radiusInKm / kmInLongitudeDegree;
minLat = lat - deltaLat;
maxLat = lat + deltaLat;
minLong = long - deltaLong;
maxLong = long + deltaLong;
For more precise calculation, look here: http://en.wikipedia.org/wiki/Longitude (section Length of a degree of longitude).
On Android, to obtain how many meters one latitude degree contains, make 2 Location
objects: one with current coordinates, and one with latitude shifted on 0.1 degree, then calculate distance between them and multiply by 10. The same with longitude.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With