gpt4 book ai didi

swift - 当我尝试放大时 map 不断反弹

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

你好,Swift 新手来了。我正在开发 map 应用程序,但我遇到区域跨度问题。我将其更改为 0.05,0.05,我希望它能够放大和缩小。然后找出当我移动时纬度和经度会发生变化。这使得我的 map 在我的代码中不断反弹到 0.05 跨度。

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

let latispan = 0.05
let longspan = 0.05

let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: latispan, longitudeDelta: longspan))
self.mapView.setRegion(region, animated: true)
//labelText.text = "\(location!.coordinate.latitude) , \(location!.coordinate.longitude)"

labelText.text = "\(region.span.latitudeDelta), \(region.span.longitudeDelta)"
//self.locationManager.stopUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Errors:" + error.localizedDescription)
}

我尝试获取当前跨度,以便稍后更改我的纬度跨度、长跨度,但我就是找不到方法。

最佳答案

尝试遵循这可能对您有帮助:)

func loadMapData() {

if let location = AppDelegate.getInstance().newlocation {
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))
self.map.setRegion(region, animated: true)
}

self.map.removeAnnotations(self.map.annotations)
self.map.showsUserLocation = true
for retailer in self.liststores {
let information = MKPointAnnotation()
information.coordinate = CLLocationCoordinate2D(latitude: retailer.retailer_lat!.doubleValue, longitude: retailer.retailer_lon!.doubleValue)
information.title = retailer.retailer_name
information.subtitle = retailer.retailer_addr1! + retailer.retailer_addr2!
self.map.addAnnotation(information)
}
}

关于swift - 当我尝试放大时 map 不断反弹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34669541/

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