当前位置标题?Mapkit

daf*_*noo -1 xcode mapkit ios swift

我正在使用MapKit创建一个应用程序.这是一个看起来如何的图像: http://i.stack.imgur.com/Dt7Qg.png

我想从该引脚更改符号当前位置的(当前位置)标题.

由于声誉,LINK发表评论

这是代码:

import UIKit
import CoreLocation
import MapKit

class ViewController: UIViewController, CLLocationManagerDelegate,    MKMapViewDelegate {

@IBOutlet weak var theMap: MKMapView!
let locationManager = CLLocationManager()

override func viewDidLoad()
{
    super.viewDidLoad()


    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.requestAlwaysAuthorization()
    locationManager.startUpdatingLocation()

    let location = self.locationManager.location

    var latitude: Double = location.coordinate.latitude
    var longitude: Double = location.coordinate.longitude

    println("GPS Súradnice :: \(latitude), \(longitude)")

    theMap.delegate = self
    theMap.mapType = MKMapType.Standard
    theMap.showsUserLocation = true


}

override func didReceiveMemoryWarning()
{
    super.didReceiveMemoryWarning()

}



//--- Find Address of Current Location ---//

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!)
{
    //--- CLGeocode to get address of current location ---//
    CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: {(placemarks, error)->Void in



        if (error != nil)
        {
            println("Reverse geocoder failed with error" + error.localizedDescription)
            return
        }

        if placemarks.count > 0
        {
            let pm = placemarks[0] as! CLPlacemark
            self.displayLocationInfo(pm)
        }
        else
        {
            println("Problem with the data received from geocoder")
        }
    })

}


func displayLocationInfo(placemark: CLPlacemark?)
{
    if let Placemark = placemark
    {
        //Stop updating kvôli vydrži baterke
        locationManager.stopUpdatingLocation()
        let adresa = (Placemark.thoroughfare != nil) ? Placemark.thoroughfare : "Ulica: "
        let cislo = (Placemark.subThoroughfare != nil) ? Placemark.subThoroughfare : "?íslo ulice:"
        let mesto = (Placemark.locality != nil) ? Placemark.locality : "Mesto: "
        let stat = (Placemark.country != nil) ? Placemark.country : "Štát: "


        var coordinates:CLLocationCoordinate2D = placemark!.location.coordinate

        var pointAnnotation:MKPointAnnotation = MKPointAnnotation()
        pointAnnotation.coordinate = coordinates
        pointAnnotation.title = "\(adresa) \(cislo)"
        pointAnnotation.subtitle = "\(adresa) \(cislo), \(mesto), \(stat)"


        self.theMap.addAnnotation(pointAnnotation)
        self.theMap.centerCoordinate = coordinates
        self.theMap.selectAnnotation(pointAnnotation, animated: true)

        println(mesto)
        println(adresa)
        println(cislo)
        println(stat)

    }

}

func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!)
{
    println("Chyba pri aktualizovaní lokácie " + error.localizedDescription)
}




}
Run Code Online (Sandbox Code Playgroud)

pat*_*lis 5

如果我做对了 你想改变蓝点.试试这个.

let theLocation: MKUserLocation = theMap.userLocation
theLocation.title = "I'm here!"
Run Code Online (Sandbox Code Playgroud)