如何在Swift上正确显示我的位置和地图?

use*_*888 2 mapkit cllocation swift

我正在尝试在应用程序Swift中显示我的位置,但这没有显示任何内容,地图全是蓝色..

我的代码是这个形式的互联网教程:

 var latitude:CLLocationDegrees = location.location.coordinate.latitude
    var longitude:CLLocationDegrees = location.location.coordinate.longitude
    var homeLati: CLLocationDegrees = 40.01540192
    var homeLong: CLLocationDegrees = 20.87901079
    var latDelta:CLLocationDegrees = 0.01
    var longDelta:CLLocationDegrees = 0.01
    var span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)

    var myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
    var region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
    self.mapKit.setRegion(region, animated: true)

    self.mapKit.showsUserLocation = true
    ///Red Pin
    var myHomePin = MKPointAnnotation()
    myHomePin.coordinate = myHome
    myHomePin.title = "Home"
    myHomePin.subtitle = "Bogdan's home"
    self.mapKit.addAnnotation(myHomePin)
Run Code Online (Sandbox Code Playgroud)

我在.split中导入了相应的配置..这段代码有什么不好的?

谢谢!

Ann*_*nnu 19

使用纬度和经度在地图上显示位置.

 var latDelta:CLLocationDegrees = 0.01

 var longDelta:CLLocationDegrees = 0.01

 var theSpan:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, longDelta)
 var pointLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(your latitude, your longitude)

 var region:MKCoordinateRegion = MKCoordinateRegionMake(pointLocation, theSpan)
  mapView.setRegion(region, animated: true)

  var pinLocation : CLLocationCoordinate2D = CLLocationCoordinate2DMake(your latitude, your longitude)
  var objectAnnotation = MKPointAnnotation()
  objectAnnotation.coordinate = pinLocation
  objectAnnotation.title = your title
  self.mapView.addAnnotation(objectAnnotation)
Run Code Online (Sandbox Code Playgroud)