使用 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/