I开发者_JS百科 am developing an iphone application which uses google API's.I have a set of latitudes and logitudes .I need to find the South west and North East points from these points .How can i do this?
thanks in advance
Given:
A point (LAT, LNG)
A distance or radius DIST
1° of latitude ~= 69 miles ~= 111 kms
1° of longitude ~= cos(latitude)*69 ~= cos(latitude)*111
The SW point is:
lng_sw = LNG - (DIST / (abs(cos(radians(LAT))) * 111))
lat_sw = LAT - (DIST / 111)
The NE point is:
lng_ne = LNG + (DIST / (abs(cos(radians(LAT))) * 111))
lat_ne = LAT + (DIST / 111)
If you use miles as your unit of measure use 69 instead of 111.
This is C# code if anybody needs
private double DegreeToRadian(double angle) {
return Math.PI * angle / 180.0;
}
private bool CalculateNeSw(double distance, double lat, double lng, out MapPoint[] points) {
/*
* 1° of latitude ~= 69 miles ~= 111 kms, 1° of longitude ~= cos(latitude)*69 ~= cos(latitude)*111
* SW.LNG = LNG - (DIST / abs(cos(radians(LAT))) * 111), SW.LAT = LAT - (DIST / 111)
* NE.LNG = LNG + (DIST / abs(cos(radians(LAT))) * 111), NE.LAT = LAT + (DIST / 111)
*/
points = new MapPoint[2];
try {
double deltaLat = distance / 69;
double deltaLng = distance / Math.Abs(Math.Cos(DegreeToRadian(lat)) * 69);
/* South-West */
points[1] = new MapPoint {
Lng = (lng - deltaLng).ToString(),
Lat = (lat - deltaLat).ToString(),
IsSet = true,
FormattedAddress = "South-West"
};
/* North-East */
points[0] = new MapPoint {
Lng = (lng + deltaLng).ToString(),
Lat = (lat + deltaLat).ToString(),
IsSet = true,
FormattedAddress = "North-East"
};
return true;
}
catch (Exception ex) {
return false;
}}
Notes:
MapPoint is a simple Data class with Lat/Lon properties
I used miles ==> 69
精彩评论