gpt4 book ai didi

ios - 将纬度和经度放在 map View 上

转载 作者:行者123 更新时间:2023-11-30 11:21:37 25 4
gpt4 key购买 nike

我试图通过插入纬度和经度在mapView中显示我想要的地方,但我失败了, map 总是显示我所在的位置,而不是我想要到达的地方

这些是我使用的代码

class MapViewController: UIViewController, CLLocationManagerDelegate{
@IBOutlet weak var map: MKMapView!
let manager = CLLocationManager()

override func viewDidLoad() {
super.viewDidLoad()

map.showsPointsOfInterest = true
map.showsUserLocation = true
manager.requestAlwaysAuthorization()
manager.requestWhenInUseAuthorization()
//user location stuff
if CLLocationManager.locationServicesEnabled() {
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.startUpdatingLocation()
}
}

func locationManager(_manager: CLLocationManager, didUpdateLocations locations:[CLLocation]) {
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01)
let location = CLLocationCoordinate2D(latitude: 36.1070, longitude: -112.1130)
let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
map.setRegion(region, animated: true)
self.map.showsUserLocation = true
}
}

最佳答案

评论此内容

map.showsUserLocation = true

并将didUpdateLocations的代码放入viewDidLoad

class MapViewController: UIViewController, CLLocationManagerDelegate{
@IBOutlet weak var map: MKMapView!
let manager = CLLocationManager()

override func viewDidLoad() {
super.viewDidLoad()

map.showsPointsOfInterest = true
//map.showsUserLocation = true
manager.requestAlwaysAuthorization()
manager.requestWhenInUseAuthorization()
//user location stuff
if CLLocationManager.locationServicesEnabled() {
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.startUpdatingLocation()
}

let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01)
let location = CLLocationCoordinate2D(latitude: 36.1070, longitude: -112.1130)
let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
map.setRegion(region, animated: true)
}

func locationManager(_manager: CLLocationManager, didUpdateLocations locations:[CLLocation]) {
///
}
}

关于ios - 将纬度和经度放在 map View 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51215637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com