如何使用swift在IOS地图上叠加图像

new*_*ift 7 mapkit ios mkoverlay swift

我试图找出如何使用SWIFT在IOS地图上叠加图像.我创建了以下代码,使用地图工具包覆盖地图上的绿色圆圈.我想用矩形图像替换绿色圆圈tOver.png 500,500我是iOS开发新手并且很快.到目前为止,我找不到一个快速的例子或好的资源.

//
//  ViewController.swift
//  mapoverlaytest
//

import UIKit
import MapKit


class ViewController: UIViewController,MKMapViewDelegate {
    @IBOutlet weak var mapView: MKMapView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.mapView.delegate = self;
        let location = CLLocationCoordinate2D(
            latitude: 51.50007773,
            longitude: -0.1246402
        )

        let span = MKCoordinateSpanMake(0.05, 0.05)
        let region = MKCoordinateRegion(center: location, span: span)

        mapView.setRegion(region, animated: true)

        let annotation = MKPointAnnotation()
        annotation.setCoordinate(location)
        annotation.title = "Big Ben"
        annotation.subtitle = "London"



        var overlay = MKCircle (centerCoordinate: location, radius: 500)

        mapView.addOverlay(overlay)

        mapView.addAnnotation(annotation)

    }

    func mapView(
        mapView: MKMapView!, rendererForOverlay
        overlay: MKOverlay!) -> MKOverlayRenderer! {
            if (overlay.isKindOfClass(MKCircle))
            {
                var circleRenderer = MKCircleRenderer(overlay: overlay)
                circleRenderer.strokeColor = UIColor.greenColor()
                circleRenderer.fillColor = UIColor(
                    red: 0,
                    green: 1.0,
                    blue: 0,
                    alpha: 0.5)

                return circleRenderer
            }
            return nil
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
Run Code Online (Sandbox Code Playgroud)

小智 0

您应该实现而不是 rendererForOverlay

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView!
Run Code Online (Sandbox Code Playgroud)

在其中,构建您的 MKAnnotationView 并在返回之前设置其图像属性。有关 MKAnnotationView 类的更多信息,请查看https://developer.apple.com/LIBRARY/ios/documentation/MapKit/Reference/MKAnnotationView_Class/index.html 。