title: Pass data to VC when google maps marker is selected Swift
body: <p>Im using the Google Maps SDK in my iOS app (in Swift) which presents a marker on the location that a user searches for (using the Google Places API), when a user then selects that marker it presents a new view controller to the screen, the problem I'm having is passing data (co-ordinates of the marker) to the new View controller (which for argument sake wants to print them to the console). </p>
  
  <p>Here's the code to place a maker on the map (I'm using GooglePlaceAutocomplete - <a href="https://github.com/watsonbox/ios_google_places_autocomplete" rel="nofollow">https://github.com/watsonbox/ios_google_places_autocomplete</a>):</p>
  
  <pre><code>// Allows user to search in search box from googlePlacesApi, when place is selected marker is placed
  func placeSelected(place: Place) {
      var latitude: Double = 0.0
      var longitude: Double = 0.0
      place.getDetails { details in
          latitude = details.latitude
          longitude = details.longitude
  
          let location = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
          self.mapView.camera = GMSCameraPosition(target: location, zoom: 15, bearing: 0, viewingAngle: 0)
          self.placeViewClosed()
          self.placeMarker(location)
      }
  </code></pre>
  
  <p>And here's the code from the Google maps view controller to present the new view when a marker is selected:</p>
  
  <pre><code>// executes when user taps custom window info above marker, presents PopooverViewController
  func mapView(mapView: GMSMapView!, didTapInfoWindowOfMarker marker: GMSMarker!) {
      let popoverContent = (self.storyboard?.instantiateViewControllerWithIdentifier("Popover"))! as UIViewController
      let nav = UINavigationController(rootViewController: popoverContent)
      nav.modalPresentationStyle = UIModalPresentationStyle.Popover
      let popover = nav.popoverPresentationController
      popoverContent.preferredContentSize = CGSizeMake(250,300)
      popover!.delegate = self
      popover!.sourceView = self.view
      popover!.sourceRect = CGRectMake(100,100,0,0)
      self.presentViewController(nav, animated: true, completion: nil)
  }  
  </code></pre>
  
  <p>I've tried using protocols but i just can't seem to pass the data! If anyone has any idea (in Swift) how to pass the data that would be appreciated! </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>In my fun placeSelected I'm now using NSUserDefaults such as:</p>
  
  <pre><code>func placeSelected(place: Place) {
      var latitude: Double = 0.0
      var longitude: Double = 0.0
      place.getDetails { details in
          latitude = details.latitude
          longitude = details.longitude
          NSUserDefaults.standardUserDefaults().setObject(longitude, forKey: "longitude")
          NSUserDefaults.standardUserDefaults().setObject(latitude, forKey: "latitude")
          let location = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
          self.mapView.camera = GMSCameraPosition(target: location, zoom: 15, bearing: 0, viewingAngle: 0)
          self.placeViewClosed()
          self.placeMarker(location)
      }
  </code></pre>
  
  <p>And I'n my new VC I'm using:</p>
  
  <pre><code>let latitude:Double =  NSUserDefaults.standardUserDefaults().objectForKey("latitude") as! Double
  let longitude:Double = NSUserDefaults.standardUserDefaults().objectForKey("longitude") as! Double 
  </code></pre>
  
  <p>Is this an acceptable way of doing it?</p>