2013-03-13 64 views
7

我需要在GMSMapView上显示一个圆圈(与MKCircle一样)。使用MKMapView和MKCircle时很容易,但不能在GMSMapView中使用MKCircle。 任何想法?如何在GMSMapView中显示一个圆圈

更新:
这是当前的(2013年3月18日)的选项:
1.含有圆图像A地面标记。
2.一个由多段(折线)组成的圆。

编辑:
3.谷歌增加了GMSCircle(2013年4月23日)

GMSGroundOverlayOptions *overlayOptions = [GMSGroundOverlayOptions options]; 
    overlayOptions.icon = [UIImage imageNamed:@"circle"]; 
    overlayOptions.position = touchMapCoordinate; 
    overlayOptions.bearing = 0; 
    overlayOptions.zoomLevel = 14.3; 
[mapView addGroundOverlayWithOptions:overlayOptions]; 

对于一个圆形图片40×40像素,它看起来OK。 (半径大约100米)

小分段路径的解决方案:

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]; 

编辑:2013年5月8日

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; 
+0

你可以发布你尝试过这么远吗? – Noich 2013-03-13 08:59:45

+0

我不知道如何开始。我想过使用GMSGroundOverlay和GMSGroundOverlayOptions添加一个圆形图标,但这意味着该圆形始终具有特定的半径。 – Bogus 2013-03-13 09:39:24

+0

感谢您的想法,它不能为iOS 8 – 2015-06-18 09:41:41

回答

7

这个问题已经过了一年多了,但Google搜索引导我到了这里,所以我想我会更新它。后人4TW!

现在有一个GMSCircle,据我所知,它可以做几乎所有的MKCircle都可以。
Google's documentation on the GMSCircle

// Build a circle for the GMSMapView 
GMSCircle *geoFenceCircle = [[GMSCircle alloc] init]; 
geoFenceCircle.radius = 130; // Meters 
geoFenceCircle.position = SOME_CLLOCATION.coordinate; // Some CLLocationCoordinate2D position 
geoFenceCircle.fillColor = [UIColor colorWithWhite:0.7 alpha:0.5]; 
geoFenceCircle.strokeWidth = 3; 
geoFenceCircle.strokeColor = [UIColor orangeColor]; 
geoFenceCircle.map = mapView; // Add it to the map. 

它在表现非常相似的MKCircle(覆盖)它与地图等的缩放级别,请无视中央的蓝色圆圈大小调整;那就是地图视图中显示的用户位置,并且我刚刚使用了GMSCircle中心点的相同坐标。

超级简单。退房的图片:

一个缩放级别: enter image description here

在这里,我们缩小了一下: enter image description here

+0

是否可以在圆上绘制文字? – 2015-10-28 11:28:05

+0

GMSOverlays具有“标题”属性,可用于向某些标记类型添加文本。如果这样不能达到你想要的效果,而且这是我过去成功完成的事情,那么你可以继承GMSMarker的子类并将图标更改为你想要的文本(你将不得不创建一个图像)它,我记得)。然后,您可以将其放置在与您的圈子相同的位置(或将该圈子添加为您的GMSMarker子类中的成员)。 https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_overlay – u2Fan 2015-10-29 13:45:35

+0

嘿,我想修复地图上的圆圈,并获得用户可以移动地图的圆圈的地方,但圆圈将保留在相同的位置有什么帮助?谢谢 - Kuldeep @ u2Fan – dreamBegin 2017-05-08 07:14:54