ios - 如何使用谷歌地图获取 map 可见区域中注释/标记的数量?

标签 ios iphone google-maps google-maps-sdk-ios

使用 MapKit ,我可以获得可见的 map 区域,然后计算其中的注释数量。但是,使用 Google map ,我无法找到任何可供引用的工作示例。首先,我知道 GMSVisibleRegion 可以用于此目的。但是无法在任何地方继续使用此操作..有人这样做过吗?有什么建议吗?

这就是我使用 Mapkit 实现的方法。我如何使用 Google map 实现此目的?

   NSMutableArray *tempArray=[[NSMutableArray alloc]init];
    for (KPAnnotation *annotation in self.mapView.annotations) {
        if (MKMapRectContainsPoint(self.mapView.visibleMapRect, MKMapPointForCoordinate(annotation.coordinate)))
        {

            NSArray *myArray = [annotation.annotations allObjects];

            int iCount=[myArray count];
            for(int i=0;i<iCount;i++)
            {
                Annotation *a=[myArray objectAtIndex:i];

                [tempArray addObject:a.name];
            }
        }
    }

最佳答案

来自安娜的评论 - 这应该可以解决问题

- (void)mapView:(GMSMapView *)mapView_ didChangeCameraPosition:(GMSCameraPosition *)position {
    [NSObject cancelPreviousPerformRequestsWithTarget:self
                                             selector:@selector(updateMapResults) object:nil];
    [self performSelector:@selector(updateMapResults) withObject:nil afterDelay:0.2];
}

- (void)updateMapResults {
    GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc]initWithRegion:mapView_.projection.visibleRegion];

    int count = 0;
    for (GMSMarker *marker in markers) {
        if([bounds containsCoordinate:marker.position]){
            count++; // update your label
        }
    }
}

关于ios - 如何使用谷歌地图获取 map 可见区域中注释/标记的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21021531/

相关文章:

javascript - 谷歌地图和引导标签

ios - 如何在 iOS 的谷歌街景 SDK 中添加 UIImageView

iphone - iOS 上不同的填充类型有什么区别?

java - 将谷歌地图航路点方向转换为通过方向

ios - 自动布局和约束的 ImageView 问题

ios - 使用未声明的标识符 'kUTTypeMovie'

iphone - 正在验证我的应用程序,我收到消息 "No identities are available for signing"

iphone - 界面生成器锁定项目位置?

javascript - 无法访问 Cloud Code Parse Framework 上的属性 "createdAt"

ios - Metal 中哪里可以使用点坐标系