UIMapKit - 从服务器获取不同区域的注释

发布于 2024-10-03 00:39:57 字数 1009 浏览 0 评论 0原文

我就会执行此操作

  1. 我有这样的代码,一旦地图加载了用户当前位置,
span.latitudeDelta = 0.2;
span.longitudeDelta = 0.2;
  1. - 我给地图一个跨度接下来,我发送带有左上角纬度、经度和右下经度、经度的 API 调用
CLLocationCoordinate2D topLeft, bottomRight;
topLeft = [mapView convertPoint:CGPointMake(0, 0) toCoordinateFromView:mapView];
CGPoint pointBottomRight = CGPointMake(mapView.frame.size.width, mapView.frame.size.height);
bottomRight = [mapView convertPoint:pointBottomRight toCoordinateFromView:mapView];
  1. 我每次都会调用此方法是区域变化
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{

问题 - 我需要从 API 获取新的图钉 - 仅当存在新区域时而不是当用户只是放大时,这意味着我不希望同一位置有多个图钉。

如果我有一个巨大的区域,比如 X,里面有 A、B、C、D。

假设我从 X 开始 - 比如说整个地球地图 - 我得到了图钉 - 现在如果用户放大缩小或执行任何我不想调用 API 的操作,因为我拥有所有图钉。

现在,如果我从 A 开始 - 突出纽约地图,然后放大(无需调用 api),但如果我移动到 B 区 - 比如说华盛顿特区 - 我需要调用 api。

我希望你能理解我的要求——任何建议。

任何帮助将不胜感激。

I have this code where I do this

  1. as soon as the map loads with users current location - I give a span to the map
span.latitudeDelta = 0.2;
span.longitudeDelta = 0.2;
  1. Next I send API call with the top left lat, lng and bottom right lat,lng
CLLocationCoordinate2D topLeft, bottomRight;
topLeft = [mapView convertPoint:CGPointMake(0, 0) toCoordinateFromView:mapView];
CGPoint pointBottomRight = CGPointMake(mapView.frame.size.width, mapView.frame.size.height);
bottomRight = [mapView convertPoint:pointBottomRight toCoordinateFromView:mapView];
  1. I call this method everytime there is a region change
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{

The Problem -
I need to get new pins from the API - only when there is a new region and not when the user just zooms in meaning i dotn want multiple pins for the same location.

If I have a huge region say X. and it has A, B, C, D inside it.

Suppose I start with X - say entire globe map - i get pins - now if the user zooms in zooms out or does whatever i never want to call the API coz i have all the pins.

Now If I start with A - juts a map of NY and I zoom in ( no need to call the api) but if I move to region B - say washington DC - i need to call the api.

I hope you understand what i am asking - any suggestions.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

裸钻 2024-10-10 00:39:57

我会做两种不同的事情来处理这个问题:

首先,将 UUID 添加到服务器上的所有注释中,以便您可以唯一地标识它们。使用 UUID 将屏幕注释存储在 NSDictionary 中。

其次,当用户缩放时,对缩放区域发出请求,并检查您下载的注释是否与词典中的任何注释匹配。如果它们匹配,则丢弃下载的数据,如果它们不匹配,则将它们添加到地图和字典中。

I would do two different things to handle this:

First, add an UUID to all your annotations on the server so that you can uniquely identify them. Use the UUID to store your on screen annotations in an NSDictionary.

Second, when a user zooms, do the request for the zoomed region and check to see if the annotations you downloaded match any of the annotations in your dictionary. If they do match, discard the downloaded data, if they don't match, add them to the map and your dictionary.

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