我需要找出地图上的可见坐标。请检查我

发布于 2024-10-25 22:17:05 字数 1044 浏览 0 评论 0原文

我需要找出地图上的可见坐标。请检查我。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不即不离 2024-11-01 22:17:05

您的代码看起来不错,但是仅获取可见部分注释的简单方法是将中心和半径直接发送到服务器。您只需选择比屏幕对角线(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文