title: Saving location coordinates to Core data- Swift 3
body: <p>I want to save location coordinates into Core Data- what is the right way of storing these and retrieving them? </p>
  
  <p>At the moment I am doing this and getting errors: </p>
  
  <pre><code>    var newPlaceCoordinate = CLLocationCoordinate2D()
        var newPlaceLatitude = CLLocationDegrees()
       var newPlaceLongitude = CLLocationDegrees()
  </code></pre>
  
  <p>I get my coordinates from using Google maps API using the autocomplete widget. </p>
  
  <pre><code>    let newPlaceCoordinate = place.coordinate
    self.newPlaceCoordinate = place.coordinate
      let newPlaceLatitude = place.coordinate.latitude
      print(newPlaceLatitude)
     self.newPlaceLatitude = place.coordinate.latitude
      let newPlaceLongitude = place.coordinate.longitude
      print(newPlaceLongitude)
  self.newPlaceLongitude = place.coordinate.longitude
  </code></pre>
  
  <p>Then to store the coordinates I use:</p>
  
  <pre><code>      let appDelegate = UIApplication.shared.delegate as! AppDelegate
      let context = appDelegate.persistentContainer.viewContext
      let newPlace = NSEntityDescription.insertNewObject(forEntityName: "StoredPlace", into: context)
       newPlace.setValue(newPlaceCoordinate, forKey: "coordinate")
      newPlace.setValue(newPlaceLatitude, forKeyPath: "latitude")
      newPlace.setValue(newPlaceLongitude, forKeyPath: "longitude")
  </code></pre>
  
  <p>And I have the attributes all set as String types.
  Then to retrieve in my ViewDidLoad I have: </p>
  
  <pre><code>      let appDelegate = UIApplication.shared.delegate as! AppDelegate
      let context = appDelegate.persistentContainer.viewContext
      let request = NSFetchRequest&lt;NSFetchRequestResult&gt;(entityName: "StoredPlace")
  
      request.returnsObjectsAsFaults = false
      if let coordinate = result.value(forKey: "coordinate") as? String
  
             {
                   let latitude = (coordinate as NSString).doubleValue
                      let longitude = (coordinate as NSString).doubleValue
                      let markers = GMSMarker()
                      markers.position = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
                      markers.icon = GMSMarker.markerImage(with: UIColor.yellow)
                      markers.tracksViewChanges = true
                      markers.map = vwGMap
                  }
  </code></pre>
  
  <p>So this is not working and producing an error of 'attribute: property = "coordinate"; desired type = NSString; given type = NSConcreteValue'. I have a few questions.</p>
  
  <p>How do I save a coordinate data appropriately? 
  Do I save it as a CLLocationDegrees or CLLocationCoordinate2D? 
  How do I convert these objects into NSString or should I be using a different type in my attributes? (I tried changing it to Double or Integer but it also produced errors). I have multiple location coordinates which I would want to store and retrieve from core data. </p>