地理空间边界框矩形计算错误:纬度不正确 [英] Geo Spacial Bounding Box Rectangle Calculation Error: Latitude Incorrect

查看:217
本文介绍了地理空间边界框矩形计算错误:纬度不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何trig或GPS专家可以帮助我吗?我试图创建一个地理空间边界框(矩形)计算,返回最大纬度和经度使用我已检索的以下方法。我调用方法一次为轴承:北,南,东和西。有了这四个值,我打算查询我的核心数据存储区中的所有对象。

Can any trig or GPS experts help me out here? I'm trying to create a geo-spacial bounding box (rectangle) calculation returning the maximum latitude and longitude using the following method that I've retrieved. I am calling the method once for each of the for bearings: north, south, east and west. With these four values I intend to query my Core Data store for all objects within the box.

  -(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偏移的计算绝对不正确。如下:

The problem is the calculation for the newLatitude offset is definitely incorrect. Given the following:

startLocation:latitude 37.331688999999997,longitude -122.030731
offsetMeters:1000
轴承:0(北)

startLocation: latitude 37.331688999999997, longitude -122.030731 offsetMeters : 1000 bearing : 0 (north)

newLatitude返回-0.36726592610659514(不正确)。

newLatitude returns -0.36726592610659514 (incorrect).

有任何建议吗?我已经编码了这个特定的公式,直到现在,这一个让我陷入困境。我也试过从PHP翻译不同的公式没有效果。

Any suggestions? I've coded around this particular formula until now and this one has me stumped. I've also tried translating a different formula from PHP to no avail. I figure the above is exactly what I need if it can be tweaked.

谢谢,
b.dot

Thanks, b.dot

推荐答案

我没有看过你的代码,但你也可以使用MapKit函数 MKCoordinateRegionMakeWithDistance()框架为你计算边界框。

I haven't looked at your code, but you could also use the MapKit function MKCoordinateRegionMakeWithDistance() to have the framework calculate a bounding box for you.

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);

这篇关于地理空间边界框矩形计算错误:纬度不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆