【发布时间】:2015-03-18 14:16:46
【问题描述】:
我在GMSMapView 上有几个GMSMarker,它们都是可拖动的,所以当我长按它们时,我可以在地图上移动它们。但是,我在 GMSMapView 上也有一个长按操作,它添加了一个标记。
- (void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker {
self.moving = YES;
}
- (void)mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker {
self.moving = NO;
}
- (void)mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate {
if (self.moving) {
return;
}
[self addMarkerAtCoordinate:coordinate];
}
现在的问题是,有时用户会误按而不是移动标记,而是添加一个新标记。因此,我想在标记周围添加小区域,用户无法添加新标记。我想过这样的事情:
- (void)mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate {
CGFloat zoomFactor = 35.f - self.mapView.camera.zoom;
CLLocation *location = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
for (GMSMarker *marker in self.markers) {
CLLocation *sectorLocation = [[CLLocation alloc] initWithLatitude:marker.position.latitude longitude:marker.position.longitude];
if ([location distanceFromLocation:sectorLocation] < zoomFactor) {
return;
}
}
}
但我当然不喜欢这种解决方案,因为该区域会随着缩放的变化而变化。我希望像标记周围的手指宽度这样的东西被长按禁止。这个距离怎么计算?
【问题讨论】:
标签: ios objective-c google-maps google-maps-api-3