【问题标题】:Identify if a user has already seen this part of the map确定用户是否已经看过这部分地图
【发布时间】:2014-02-02 21:56:58
【问题描述】:

我目前正在开发一个应用程序,但在注释性能方面遇到了障碍。

目前,我有这个代码:

-(void) getStationsWithRadius:(float)distance //distanceInMetres
{
    distance = (distance/1000.0f);
    CLLocation *loc = [[CLLocation alloc] initWithLatitude:[mkMapView centerCoordinate].latitude longitude:[mkMapView centerCoordinate].longitude];
    ///....Network stuff....
}

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{

    MKMapRect mRect = mapView.visibleMapRect;
    MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect));
    MKMapPoint westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect));

    zoomDistance = MKMetersBetweenMapPoints(eastMapPoint, westMapPoint); //In Meters
    [self getAnnotationsWithRadius:zoomDistance];
//etc.....

简而言之,每次用户更改地图上的区域时,我希望应用程序根据MKMapView 坐标的中心和缩放距离(半径)查询服务器以获取注释。

这显然对服务器造成了很大的负担,因为即使地图移动的最轻微变化也会导致应用程序请求注释。

有没有办法确定用户是否已经为他们当前所在的地图视图加载了注释?

【问题讨论】:

    标签: ios objective-c mkmapview


    【解决方案1】:

    通过包围矩形来请求注释,而不是通过中心和半径。存储您收到的所有注释,由 x 和 y 点索引。将您请求注释的矩形存储在一个智能结构中,该结构将合并形成更大矩形的矩形。

    每当用户移动地图时,您只需检查您的结构以查看当前区域内的所有内容是否已被请求,如果是,则只需查找 x 范围和 y 范围内的所有注释并将它们逻辑“与”在一起。

    如果没有,请获取您缺少的矩形部分中的注释,并标记您现在已获取该矩形。

    【讨论】:

      猜你喜欢
      • 2021-07-13
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 2022-07-28
      • 1970-01-01
      • 2013-07-13
      • 1970-01-01
      相关资源
      最近更新 更多