【发布时间】:2009-10-22 08:38:07
【问题描述】:
我正在开发一个使用 google API 的 iphone 应用程序。我有一组纬度和对数。我需要从这些点找到西南和东北点。我该怎么做?
提前致谢
【问题讨论】:
标签: iphone
我正在开发一个使用 google API 的 iphone 应用程序。我有一组纬度和对数。我需要从这些点找到西南和东北点。我该怎么做?
提前致谢
【问题讨论】:
标签: iphone
鉴于:
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
SW 点是:
lng_sw = LNG - (DIST / (abs(cos(radians(LAT))) * 111))
lat_sw = LAT - (DIST / 111)
NE 点是:
lng_ne = LNG + (DIST / (abs(cos(radians(LAT))) * 111))
lat_ne = LAT + (DIST / 111)
如果您使用英里作为度量单位,请使用 69 而不是 111。
【讨论】:
如果有人需要,这是 C# 代码
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;
}}
注意事项:
MapPoint 是一个具有 Lat/Lon 属性的简单 Data 类
我用了英里 ==> 69
【讨论】: