【发布时间】:2013-03-01 02:24:17
【问题描述】:
我需要在 GMSMapView 上显示一个圆圈(与 MKCircle 一样)。这在使用 MKMapView 和 MKCircle 时很容易,但不能将 MKCircle 与 GMSMapView 一起使用。 有任何想法吗?
更新:
这是当前 (18.03.2013) 选项:
1. 包含圆形图像的地面标记。
2. 一个由几段组成的圆(折线)。
编辑:
3. Google 添加了 GMSCircle (23.04.2013)
GMSGroundOverlayOptions *overlayOptions = [GMSGroundOverlayOptions options];
overlayOptions.icon = [UIImage imageNamed:@"circle"];
overlayOptions.position = touchMapCoordinate;
overlayOptions.bearing = 0;
overlayOptions.zoomLevel = 14.3;
[mapView addGroundOverlayWithOptions:overlayOptions];
对于 40x40 像素的圆形图像,它看起来不错。 (半径约为 100 m)
小分段路径解决方案:
GMSPolylineOptions *circle = [GMSPolylineOptions options];
CGPoint touchPoint = [mapView.projection pointForCoordinate:touchMapCoordinate];
GMSMutablePath *path = [GMSMutablePath path];
CGPoint circlePoint;
for (int i = 0; i < 360; i++)
{
circlePoint.x = touchPoint.x + radius * cos(i*M_PI/180);
circlePoint.y = touchPoint.y + radius * sin(i*M_PI/180);
CLLocationCoordinate2D aux = [mapView.projection coordinateForPoint:circlePoint];
[path addCoordinate:aux];
}
circle.path = path;
circle.width = 1;
[mapView addPolylineWithOptions:circle];
编辑:08.05.2013
GMSCircle 解决方案:
CLLocationCoordinate2D circleCenter = CLLocationCoordinate2DMake(latitude, longitude);
GMSCircle *circ = [GMSCircle circleWithPosition:circleCenter
radius:1000];
circ.fillColor = [UIColor blueColor];
circ.strokeColor = [UIColor redColor];
circ.strokeWidth = 5;
circ.map = mapView;
【问题讨论】:
-
你能公布你到目前为止的尝试吗?
-
我什至不知道如何开始。我考虑过使用 GMSGroundOverlay 和 GMSGroundOverlayOptions 添加一个圆形图标,但这意味着该圆形始终具有特定的半径。
-
它不适用于 iOS 8
标签: ios google-maps google-maps-sdk-ios