J'essaie d'ajouter les broches à la carte en utilisant le tableau de chaînes. mais il n'affiche qu'une seule broche qui n'affiche pas la deuxième broche sur la carte.Comment faire pour déposer des broches sur plusieurs emplacements mapkit swift
func getDirections(enterdLocations:[String]) {
let geocoder = CLGeocoder()
// array has the address strings
for (index, item) in enterdLocations.enumerated() {
geocoder.geocodeAddressString(item, completionHandler: {(placemarks, error) -> Void in
if((error) != nil){
print("Error", error)
}
if let placemark = placemarks?.first {
let coordinates:CLLocationCoordinate2D = placemark.location!.coordinate
let dropPin = MKPointAnnotation()
dropPin.coordinate = coordinates
dropPin.title = item
self.myMapView.addAnnotation(dropPin)
self.myMapView.selectAnnotation(dropPin, animated: true)
}
})
}
}
et ma fonction d'appel
@IBAction func findNewLocation()
{
var someStrs = [String]()
someStrs.append("6 silver maple court brampton")
someStrs.append("shoppers world brampton")
getDirections(enterdLocations: someStrs)
}
Merci. pouvez-vous m'aider à tracer la route entre les broches qui sont dans le tableau. –
Jetez un oeil à quelque chose comme: https://www.hackingwithswift.com/example-code/location/how-to-find-directions-using-mkmapview-and-mkdirectionsrequest – Ladislav