我需要找出地图上的可见坐标。请检查我
我需要找出地图上的可见坐标。请检查我。
CLLocationDegrees leftDegrees = mapView.region.center.longitude - (mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees rightdegrees = mapView.region.center.longitude + (mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees bottomDegrees = mapView.region.center.latitude - (mapView.region.span.latitudeDelta / 2.0);
CLLocationDegrees topDegrees = mapView.region.center.latitude + (mapView.region.span.latitudeDelta / 2.0);
if (leftDegrees > rightdegrees)
{
[self getAnnotationFromServer: mapView.region.center andLeftDegrees:leftDegrees andRightDegrees:180 andBottomDegrees:bottomDegrees andTopDegrees:topDegrees];
[self getAnnotationFromServer: mapView.region.center andLeftDegrees:rightdegrees andRightDegrees:-180 andBottomDegrees:bottomDegrees andTopDegrees:topDegrees];
}
else
{
[self getAnnotationFromServer: mapView.region.center andLeftDegrees:leftDegrees andRightDegrees:rightdegrees andBottomDegrees:bottomDegrees andTopDegrees:topDegrees];
}
I need to figure out visible coordinates on map. Please, check me.
CLLocationDegrees leftDegrees = mapView.region.center.longitude - (mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees rightdegrees = mapView.region.center.longitude + (mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees bottomDegrees = mapView.region.center.latitude - (mapView.region.span.latitudeDelta / 2.0);
CLLocationDegrees topDegrees = mapView.region.center.latitude + (mapView.region.span.latitudeDelta / 2.0);
if (leftDegrees > rightdegrees)
{
[self getAnnotationFromServer: mapView.region.center andLeftDegrees:leftDegrees andRightDegrees:180 andBottomDegrees:bottomDegrees andTopDegrees:topDegrees];
[self getAnnotationFromServer: mapView.region.center andLeftDegrees:rightdegrees andRightDegrees:-180 andBottomDegrees:bottomDegrees andTopDegrees:topDegrees];
}
else
{
[self getAnnotationFromServer: mapView.region.center andLeftDegrees:leftDegrees andRightDegrees:rightdegrees andBottomDegrees:bottomDegrees andTopDegrees:topDegrees];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码看起来不错,但是仅获取可见部分注释的简单方法是将中心和半径直接发送到服务器。您只需选择比屏幕对角线(latitudeDelta 或 longitudeDelta)稍大的半径,然后乘以常数即可。
这也对服务器有帮助,因为您可以轻松找到计算点之间距离的函数,而不必关心 180/-180 交汇点。
Your code looks good, but an easy way to get annotations only for the visible part would be directly send the center and the radius to the server. you just have to choose a radius a little bigger than the screen diagonal (latitudeDelta or longitudeDelta) that you multiply by a constant.
This will also help the server because you can easely find functions tu compute distance between points and don't have to take care about the 180/-180 junction.