我有两个注释。注释上有图像。我希望图像朝向MapBox中的路线。
这是我尝试过的:
func drawAnnoation (orgin :CLLocationCoordinate2D ,destination :CLLocationCoordinate2D){
if annotation == nil {
annotation = CameraAnnotation(coordinate: orgin, title: "SOURCE", subtitle: "D", image:"selfImage" )
let source = orgin
annotation.coordinate = source
annotation.title = "ddd"
map.setCenter(orgin, zoomLevel: 18, animated: false)
map.addAnnotation(annotation)
} else {
UIView.animate(withDuration: 1.5, animations: {
// Here Core Animation calls MapBox using an implicit animation.
self.annotation.coordinate = orgin
})
}
if annotations == nil {
let annotations = NoteAnnotation(coordinate: destination, title: "DESTINATION", subtitle: "E", image: "car")
let sources = destination
annotations.coordinate = sources
annotations.title = "d"
map.addAnnotation(annotations)
}
}
func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
guard annotation is CameraAnnotation || annotation is NoteAnnotation else {
return nil
}
if annotation is CameraAnnotation {
return dview
} else {
return sdview
}
}
请帮助实现该目标。
答案 0 :(得分:0)
您的意思是看起来像Uber ...当路线移动时,应同时处理您的注释。
我假设您需要使用Socket for iOS,在其中您可以从套接字获取纬度和经度,然后使用注释设置纬度和经度。
让source = CLLocation(纬度:Socket_latitiude_value,经度:Socket_longitude_value)
如果注释==无{ let注解= NoteAnnotation(坐标:sources,标题:“ DESTINATION”,副标题:“ E”,图片:“ car”) 注解。坐标=来源 注解.title =“ d” map.addAnnotation(annotations) }
答案 1 :(得分:0)
我已经通过使用Google Map API做到了。在此应用程序https://www.pulzpluz.com/
中