b.d*_*dot 6 iphone gps core-data objective-c geolocation
任何触发或GPS专家都可以帮助我吗?我正在尝试创建一个地理空间边界框(矩形)计算,使用我检索到的以下方法返回最大纬度和经度.我为每个轴承调用一次方法:北,南,东和西.有了这四个值,我打算在我的Core Data存储库中查询框中的所有对象.
-(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;
}
Run Code Online (Sandbox Code Playgroud)
问题是newLatitude偏移的计算肯定是不正确的.鉴于以下内容:
startLocation:北纬37.331688999999997,经度-122.030731 offsetMeters:1000轴承:0(北)
newLatitude返回-0.36726592610659514(不正确).
有什么建议?到目前为止,我已经围绕这个特殊的公式进行了编码,这个让我难过.我也试过从PHP翻译不同的公式无济于事.我认为如果它可以调整,上面正是我需要的.
谢谢,b.dot
Ole*_*ann 13
我没有查看你的代码,但你也可以使用MapKit函数MKCoordinateRegionMakeWithDistance()让框架为你计算一个边界框.
CLLocationCoordinate2D center = { 37.3, -122.0 };
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, 2000.0, 2000.0);
CLLocationCoordinate2D northWestCorner, southEastCorner;
northWestCorner.latitude = center.latitude - (region.span.latitudeDelta / 2.0);
northWestCorner.longitude = center.longitude + (region.span.longitudeDelta / 2.0);
southEastCorner.latitude = center.latitude + (region.span.latitudeDelta / 2.0);
southEastCorner.longitude = center.longitude - (region.span.longitudeDelta / 2.0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3634 次 |
| 最近记录: |