qetinac qetinac - 4 months ago 8
iOS Question

how to display Single Location on mapview in iOs?

How can i display single Location with Longitude, Latitude coordinates on Mapview (NOT my current location!)? I want to display only single Location with these random coordinates- When these coorditanes change, the old position on map view has to be removed and replaced with new coordinates? How can i do that ?

Thanks!

Rob Rob
Answer

To add an annotation:

let annotation = MKPointAnnotation()
annotation.title = title
annotation.coordinate = coordinate
mapView.addAnnotation(annotation)

You can then either remove it with removeAnnotation and add a new annotation, or you can animate its moving to a new coordinate:

UIView.animateWithDuration(1.0) {
    annotation.coordinate = newCoordinate
}

enter image description here