【发布时间】:2011-01-25 10:48:16
【问题描述】:
任何三角或 GPS 专家可以在这里帮助我吗?我正在尝试使用我检索到的以下方法创建一个地理空间边界框(矩形)计算,以返回最大纬度和经度。我为每个轴承调用一次该方法:北、南、东和西。使用这四个值,我打算在我的核心数据存储中查询框内的所有对象。
-(CLLocation*) offsetLocation:(CLLocation*)startLocation:(double)offsetMeters:(double)bearing {
double EARTH_MEAN_RADIUS_METERS = 6372796.99;
double newLatitude = asin( sin(startLocation.coordinate.latitude) * cos(offsetMeters/EARTH_MEAN_RADIUS_METERS) + cos(startLocation.coordinate.latitude) * sin(offsetMeters/EARTH_MEAN_RADIUS_METERS) * cos(bearing) );
double newLongitude = startLocation.coordinate.longitude + atan2( sin(bearing) * sin(offsetMeters/EARTH_MEAN_RADIUS_METERS) * cos(startLocation.coordinate.latitude), cos(offsetMeters/EARTH_MEAN_RADIUS_METERS) - sin(startLocation.coordinate.latitude) * sin(newLatitude));
CLLocation *tempLocation = [[CLLocation alloc] initWithLatitude:newLatitude longitude:newLongitude];
[tempLocation autorelease];
return tempLocation;
}
问题是 newLatitude 偏移量的计算绝对不正确。鉴于以下情况:
startLocation:纬度37.331688999999997,经度-122.030731 偏移量:1000 方位:0(北)
newLatitude 返回 -0.36726592610659514(不正确)。
有什么建议吗?到目前为止,我已经围绕这个特定的公式进行了编码,这个公式让我很难过。我也尝试过从 PHP 翻译不同的公式,但无济于事。如果可以调整,我认为以上正是我所需要的。
谢谢, b.dot
【问题讨论】:
标签: iphone objective-c core-data geolocation gps