我一直在尝试将地图上的注释(自定义)从一个坐标移动到另一个坐标,但找不到更好的方法。我在网上搜索过但找不到任何有用的东西。
任何成功实施此类功能的人(在swift中)?
修改
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];
}
CustomAnnotation
class CustomAnnotation: MKPointAnnotation {
var imageName: String!
}
当我运行代码时,我所能看到的只是坐标route[0]
处的注释。如果注释确实移动了,那么至少它应该在坐标route[route.count-1]
但不是route[0]
答案 0 :(得分: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
}
答案 1 :(得分:-1)
[UIView animateWithDuration:5.0
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
[CarAnnotationView.annotation setCoordinate:newCoord];
} completion:nil];