繁体   English   中英

从CLLocationCoordinate2D查找边界框

[英]Finding Bounding Box from CLLocationCoordinate2D

我正在使用一个API,该API允许我指定坐标的“边界框”,该坐标仅允许我在该框内返回结果:

  • 返回指定边界框内的地理缓存列表,该列表按距框中心的距离排序。
  • 参数南纬,西经,北纬,东经定义边界框的边缘。
  • 坐标应为十进制度数。北纬和东经使用正数,南纬和西经使用负数。
  • 盒子不能越过180度经度线或90度或-90度点。

算术运算超出了我,但我发现了一些有用的计算,但是我不确定这是API所需的:

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(self.mapView.centerCoordinate, 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);

有人知道我该怎么做吗? 为了获得定义边界框边缘的west longitude, north latitude, east longitude此处的计算是否有用?

编辑:

我得到的错误:

Invalid value for parameter: bbox=south,west,north,east

使用中心值:

center=37.552821,-122.377413

转换后的盒子(经过上面的计算):

bbox=37.561831,-122.388730,37.543811,-122.366096

最终工作代码:

// Current distance
MKMapRect mRect = mapView.visibleMapRect;
MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect));
MKMapPoint westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect));
CLLocationDistance distance = MKMetersBetweenMapPoints(eastMapPoint, westMapPoint);

// Region
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(request.center, distance, distance);
CLLocationCoordinate2D northWestCorner, southEastCorner;
northWestCorner.latitude  = request.center.latitude  + (region.span.latitudeDelta  / 2.0);
northWestCorner.longitude = request.center.longitude - (region.span.longitudeDelta / 2.0);
southEastCorner.latitude  = request.center.latitude  - (region.span.latitudeDelta  / 2.0);
southEastCorner.longitude = request.center.longitude + (region.span.longitudeDelta / 2.0);
base = [base stringByAppendingFormat:@"bbox=%f,%f,%f,%f&", southEastCorner.latitude,northWestCorner.longitude,northWestCorner.latitude,southEastCorner.longitude];

您似乎已经扭转了半球。 北方和东方是积极的。 因此,如果您从中心纬度开始,并且想要找到北边界,则可以将三角洲增加一半,而不是减去。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM