Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the max latitude and longitude given radius (meters) and position

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!!

like image 416
Gio Avatar asked Dec 08 '22 08:12

Gio


1 Answers

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.

like image 86
Alex Salauyou Avatar answered Dec 10 '22 21:12

Alex Salauyou