我正在尝试在 Swift 应用程序中显示我的位置,但这没有显示任何内容, map 全是蓝色的..
我的代码是这个形式的互联网教程:
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)
我已经在 .split. 中导入了相应的配置。这段代码有什么问题?
谢谢!
最佳答案
使用纬度和经度在 map 上显示位置。
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)
关于swift - 如何在 Swift 上正确显示我的位置和 map 中的图钉?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24780325/