我正在使用一个API,允许我指定一个坐标的“边界框”,这样我只能在该框中返回结果:
这方面的数学有点超出我的意见,但我发现有些有用的计算,但我不确定这是我对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];
答案 0 :(得分:2)
你似乎已经扭转了你的半球。北部和东部都是积极的。因此,如果您从中心纬度开始,并且想要找到北边界,则将ADD的一半加上,而不是减去。