gpt4 book ai didi

swift:将注释从一个坐标移动到另一个坐标

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

我一直在尝试将 map 上的注释(自定义)从一个坐标移动到另一个坐标,但找不到更好的方法。我在网上搜索过,但找不到任何有用的信息。

有人成功地实现了此类功能(快速)吗?

编辑

var annMove: CustomAnnotation = CustomAnnotation();
annMove.title = "Moving annotation"
annMove.subtitle = ""
annMove.imageName = "blue_pin.png"
self.mapView.addAnnotation(annMove);
for i in 0..<route.count
{
annMove.coordinate = route[i];
}

自定义注释

class CustomAnnotation: MKPointAnnotation {
var imageName: String!

}

当我运行代码时,我只能看到坐标 route[0] 处的注释。如果注释确实移动了,那么至少它应该位于坐标 route[route.count-1] 处,而不是 route[0]

最佳答案

我希望这会有所帮助。它对我有用。

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

var userLocation: CLLocation = locations[0] as! CLLocation

var latitude = userLocation.coordinate.latitude
var longitude = userLocation.coordinate.longitude

var latDelta:CLLocationDegrees = 0.05
var lonDelta: CLLocationDegrees = 0.05

var span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
var location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
var region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)

self.map.setRegion (region, animated: false)
}

override func viewDidLoad() {
super.viewDidLoad()

locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
map.showsUserLocation = true
}

关于swift:将注释从一个坐标移动到另一个坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27453330/

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