简体   繁体   English

[iPhone]在Google地图上的某个位置绘制圆圈

[英][iPhone]draw the circle around a location on google map

I am new to iPhone programming. 我是iPhone编程的新手。 I want to write an application using CoreLocation and Mapkit API. 我想使用CoreLocation和Mapkit API编写应用程序。 I have been able to find and add pins for the current location. 我已经能够找到并添加当前位置的图钉。 Now, I am trying to draw a circle around the location, but I am not sure how to go about doing that. 现在,我试图在该位置周围画一个圆,但是我不确定该怎么做。 I'd appreciate any pointers, thanks. 谢谢您的指点,谢谢。

I thought i have got same question with you. 我以为我也有同样的问题。 And i have found this questions answer, it was helped me a lot, i hope this will be help to you. 我找到了这个问题的答案,这对我有很大帮助,希望对您有所帮助。 Drawing a Point, Line, Polygon on top of MKMapview 在MKMapview顶部绘制点,线,多边形

I know this was originally tagged iOS SDK 3.0 , but I assume that was because at the time, that was the current SDK. 我知道它最初被标记为iOS SDK 3.0 ,但是我认为那是因为当时是当前的SDK。 If somebody is looking for the answer to this, but can use iOS 4.0+, then here's my solution. 如果有人正在寻找答案,但可以使用iOS 4.0+,那么这就是我的解决方案。

So, I assume you have a UIViewController , that owns a MKMapView . 因此,我假设您有一个UIViewController ,它拥有一个MKMapView

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

and you setup your connections in Interface Builder (XCode now) to connect the actual MKMapView to the mapView outlet. 并在Interface Builder (现在为XCode)中设置连接,以将实际的MKMapView连接到mapView出口。 And then you have some variable that contains the location you want to draw a circle around: location . 然后,您将具有一些变量,其中包含要在其周围绘制圆的locationlocation You simply need to create a MKCircle , and add it to your mapView as an overlay : 您只需要创建一个MKCircle ,并将其作为叠加层添加到您的mapView中:

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

If you want to customize the look of your circle, your view controller could implement MKMapViewDelegate and implement mapView:viewForOverlay: like so: 如果要自定义圆的外观,则视图控制器可以实现MKMapViewDelegate并实现mapView: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;
}

Remember to set mapView.delegate = self in the view controller code (eg viewDidLoad ) or graphically via Interface Builder . 请记住在视图控制器代码(例如viewDidLoad )中或通过Interface Builder以图形方式设置mapView.delegate = self

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM