问题描述
我需要在GMSMapView上显示一个圆圈(与MKCircle一样)。使用MKMapView和MKCircle时很容易,但不能在GMSMapView中使用MKCircle。
任何想法?
更新:
这是当前(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米)
细分路径解决方案:
GMSPolylineOptions * circle = [GMSPolylineOptions options];
CGPoint touchPoint = [mapView.projection pointForCoordinate:touchMapCoordinate];
GMSMutablePath * path = [GMSMutablePath path];
CGPoint circlePoint; (int i = 0; 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;
目前SDK不支持圈子,但有一项功能请求可在此处添加圈子:
在此期间,您可以通过绘制多段线来创建一个圆圈,并有几个短段?
I need to display a circle (as with MKCircle) on a GMSMapView. This is easy when using a MKMapView and MKCircle, but can't use MKCircle with GMSMapView.Any ideas?
Update:
This are the current(18.03.2013) options:
1. A ground marker containing a circle image.
2. A a circle made with several segments (polyline).
Edit:
3. Google added a 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];
For a circle image 40x40 pixels it looks ok. (radius is approximately 100 m)
Small segmented path solution:
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];
EDIT : 08.05.2013
GMSCircle solution:
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;
At the moment the SDK doesn't support circles, but there is a feature request to add circles here:
https://code.google.com/p/gmaps-api-issues/issues/detail?id=4971
In the meantime you could maybe fake a circle by drawing a polyline, with several short segments?
这篇关于如何在GMSMapView中显示一个圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!