Ich arbeite an einer Kartenanwendung, bisher habe ich die Möglichkeit, Pins (Stifte sind Speicher genannt) zu löschen. Ich möchte die Pinkoordinateninformationen für jeden abgelegten Pin in einer neuen Szene anzeigen, so dass der Benutzer eine Übersicht über seine fallengelassenen Pins sehen kann. Wie würde ich das machen?Drucken von Koordinateninformationen an den Benutzer, Swift
Ich habe den Hauptansichtcontroller eingerichtet und eine neue Szene hinzugefügt, die modal angezeigt wird. Bisher habe ich den folgenden Code haben Lage und zu Tropfen/stores Pindaten zu verwalten:
@IBOutlet weak var addButton: UIBarButtonItem!
// Add button action
@IBAction func addButton(sender: AnyObject) {
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: self.placesMap.userLocation.coordinate.latitude, longitude: self.placesMap.userLocation.coordinate.longitude)
self.placesMap.addAnnotation(annotation)
self.locationManager.startUpdatingLocation()
}
// Location function
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.004, longitudeDelta: 0.004))
self.placesMap?.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
let locationDictionary:[String:Double] = ["latitude":center.latitude,"longitude":center.longitude]
var locationArray = [[String:Double]]()
if NSUserDefaults.standardUserDefaults().objectForKey("locationArray") != nil {
locationArray = NSUserDefaults.standardUserDefaults().objectForKey("locationArray") as! [[String:Double]]
}
locationArray.append(locationDictionary)
NSUserDefaults.standardUserDefaults().setObject(locationArray, forKey: "locationArray")
NSUserDefaults.standardUserDefaults().synchronize()
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
print("Error code: " + error.localizedDescription)
}