0

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

任何成功实现此类功能的人(迅速)?

编辑

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]

4

2 回答 2

2

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

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
}
于 2015-07-11T13:45:37.963 回答
-1
[UIView animateWithDuration:5.0
                                  delay:0.0
                                options:UIViewAnimationOptionCurveLinear
                             animations:^{
                                 [CarAnnotationView.annotation setCoordinate:newCoord];
                             } completion:nil];
于 2016-09-01T09:16:57.177 回答