gpt4 book ai didi

ios - map View 相机航向问题

转载 作者:IT王子 更新时间:2023-10-29 05:50:12 26 4
gpt4 key购买 nike

我对设置 UIMapView 的顺序/方式有疑问。这是我希望发生的事情:

出现 View - map 旋转到指定标题

点击重置按钮 - 如果用户移动了 map ,它将重置为默认航向和缩放

目前 map 出现时, map 旋转到航向,但重置按钮没有任何作用。我怀疑这取决于我做事的顺序,因为如果我翻转两行代码,它就可以工作,但是本地图出现时它不会旋转到正确的航向。

这是我的代码:

@IBAction func rotateToDefault(sender: AnyObject) {
mapView.setRegion(zoomRegion, animated: true)
mapView.camera.heading = parkPassed.orientation!
}

override func viewWillAppear(animated: Bool) {
setUpMapView()
}

override func viewDidAppear(animated: Bool) {
mapView.setRegion(zoomRegion, animated: true)
mapView.camera.heading = parkPassed.orientation!
}

func setUpMapView() {
rideArray = ((DataManager.sharedInstance.rideArray) as NSArray) as! [Ride]

zoomRegion = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2D(latitude: parkPassed.latitude!, longitude: parkPassed.longitude!), 1000, 1000)
mapView.setRegion(zoomRegion, animated: true)
mapView.delegate = self

for ride in rideArray {
var subtitle = ""
if locationManager.location == nil {
subtitle = "Distance unavailable"
} else {
let userLocation = CLLocation(latitude: locationManager.location.coordinate.latitude, longitude: locationManager.location.coordinate.longitude)
let annotationLocation = CLLocation(latitude: ride.latitude!, longitude: ride.longitude!)

var distance = Int(CLLocationDistance(annotationLocation.distanceFromLocation(userLocation)))

if distance > 1000 {
distance = distance / 1000
subtitle = "\(distance) kilometers"
} else {
subtitle = "\(distance) meters"
}
}

let annotation = RideAnnotation(coordinate: CLLocationCoordinate2DMake(ride.latitude!, ride.longitude!), title: ride.name!, subtitle: subtitle)
self.qTree.insertObject(annotation)
annotationsAdded.insertObject(annotation, atIndex: 0)

println(qTree.count)
}
}

有人有什么建议吗?

最佳答案

我遇到了类似的问题。

region 和 camera 似乎是两个相互排斥的概念,它们决定了您如何查看 map 的哪一部分。

如果你使用区域,你有坐标和跨度来确定你看到的是什么(你已经在你的代码中这样做了)

如果您使用相机,您可以使用坐标、距离、俯仰和航向来确定您如何查看 map 。

使用 mapView.setCamera(...) 平滑地更改您看到的内容,包括标题。

要定义你的相机 View ,你可以做类似的事情

let camera = MKMapCamera(lookingAtCenterCoordinate: userLocation, fromDistance: 1000, pitch: 0, heading: heading)
self.mapView.setCamera(camera, animated: false)

来自苹果文档:

Assigning a new camera to this property updates the map immediately and without animating the change. If you want to animate changes in camera position, use the setCamera:animated: method instead.

关于ios - map View 相机航向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31886847/

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