2016-06-28 4 views
1

사용자 위치에서 고유 한 원하는 위치에 투명 원 또는 사각형을 표시하는 방법을 파악하는 데 문제가 있습니다. Im mapkit 초보자 그래서 미리 감사드립니다.mapkit 및 swift를 사용하여 설정된 위치에 원을 오버레이하는 방법

class FirstViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate 
{ 

@IBOutlet weak var mapView: MKMapView! 

let locationManager = CLLocationManager() 

override func viewDidLoad() 
{ 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    self.locationManager.delegate = self 
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest 
    self.locationManager.requestAlwaysAuthorization() 
    self.locationManager.startUpdatingLocation() 
    self.mapView.showsUserLocation = true 

} 
override func didReceiveMemoryWarning() 
{ 
    super.didReceiveMemoryWarning() 
} 
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) 
{ 
    let location = locations.last 
    let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude) 
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1)) 
    self.mapView.setRegion(region, animated: true) 
    self.locationManager.stopUpdatingLocation()// 
} 
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) 
{ 
    print("Errors: " + error.localizedDescription) 
} 

} 

답변

2

확실히 MapKit을 가져 왔습니다.

class Map { 

    func setup() { 
     // Assign delegate here. Can call the circle at startup, or at a later point using the method below. Includes <# #> syntax to simplify code completion. 
     mapView.delegate = self 
     showCircle(<#CLLocationCoordinate2D#>, radius: <#CLLocationDistance#>) 
    } 

    // Radius is measured in meters 
    func showCircle(coordinate: CLLocationCoordinate2D, radius: CLLocationDistance) { 
     let circle = MKCircle(centerCoordinate: coordinate, radius: radius) 
     mapView.addOverlay(circle) 
    } 
} 

extension Map: MKMapViewDelegate { 
    func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer { 
     // If you want to include other shapes, then this check is needed. If you only want circles, then remove it. 
     if let circleOverlay = overlay as? MKCircle { 
      let circleRenderer = MKCircleRenderer(overlay: circleOverlay) 
      circleRenderer.fillColor = UIColor.blackColor() 
      circleRenderer.alpha = 0.1 

      return circleRenderer 
     } 

     // You can either return your square here, or ignore the circle check and only return circles. 
     return <#Another overlay type#> 
    } 
} 
+0

또 다른 옵션은 해당 원의 이미지로 맞춤 주석을 만드는 것입니다. 나는 당신이 그 유형의 기능을 원했던 조건 아래서 이것을 던지고 있습니다. – Sethmr

관련 문제