【问题标题】:[iPhone]draw the circle around a location on google map[iPhone]在谷歌地图上画圈
【发布时间】:2009-10-07 09:47:35
【问题描述】:

我是 iPhone 编程的新手。我想使用 CoreLocation 和 Mapkit API 编写一个应用程序。 我已经能够为当前位置找到并添加图钉。现在,我正在尝试在该位置周围画一个圆圈,但我不知道该怎么做。不胜感激,谢谢。

【问题讨论】:

    标签: ios mapkit mkoverlay


    【解决方案1】:

    我想我和你有同样的问题。我找到了这个问题的答案,它对我有很大帮助,我希望这对你有帮助。 Drawing a Point, Line, Polygon on top of MKMapview

    【讨论】:

      【解决方案2】:

      我知道这最初被标记为 iOS SDK 3.0,但我认为那是因为当时那是当前的 SDK。如果有人正在寻找这个问题的答案,但可以使用 iOS 4.0+,那么这就是我的解决方案。

      所以,我假设你有一个UIViewController,它拥有一个MKMapView

        @interface MapViewController : UIViewController<MKMapViewDelegate> {
        @private
          MKMapView* mapView;
        }
        @property (nonatomic, retain) IBOutlet MKMapView* mapView;
        @end
      

      然后您在 Interface Builder(现在是 XCode)中设置连接以将实际的 MKMapView 连接到 mapView 出口。然后你有一些变量,其中包含你想在周围画一个圆圈的位置:location。您只需创建一个MKCircle,并将其作为叠加层添加到您的mapView

        CLLocationCoordinate2D location = [self getTheLocationSomehow];
        CLLocationDistance radius = 50.0;   // in meters
        MKCircle* circle = [MKCircle circleWithCenterCoordinate: location radius: radius];
        [mapView addOverlay:circle];
      

      如果你想自定义你的圆圈的外观,你的视图控制器可以像这样实现MKMapViewDelegatemapView:viewForOverlay:

      - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
          MKCircle* circle = overlay;
          MKCircleView* circleView = [[[MKCircleView alloc] initWithCircle: circle] autorelease];
          // make the circle red with some transparency and stroke
          circleView.fillColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.25];
          circleView.strokeColor = [UIColor redColor];
          circleView.lineWidth = 2.0;
      
          return circleView;
      }
      

      记得在视图控制器代码中设置mapView.delegate = self(例如viewDidLoad)或通过Interface Builder以图形方式设置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多