Skip to content

Instantly share code, notes, and snippets.

@ziyang0621
Created October 29, 2015 21:40
Show Gist options
  • Save ziyang0621/b016214c5e689b88299f to your computer and use it in GitHub Desktop.
Save ziyang0621/b016214c5e689b88299f to your computer and use it in GitHub Desktop.
mport UIKit
import GoogleMaps
class ViewController: UIViewController {
let locationManager = CLLocationManager();
var placesClient: GMSPlacesClient?
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
self.view = mapView
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
locationManager.requestAlwaysAuthorization()
placesClient = GMSPlacesClient()
testPlace()
}
func testPlace() {
placesClient?.currentPlaceWithCallback { (placeLikelihoodList: GMSPlaceLikelihoodList?, error: NSError?) -> Void in
if error != nil {
print("Current Place error: \(error!.localizedDescription)")
return
}
if let placeLicklihoodList = placeLikelihoodList {
let place = placeLicklihoodList.likelihoods.first?.place
if let place = place
{
print("Current Place address \(place.formattedAddress)")
print("Current Place attributions \(place.attributions)")
print("Current PlaceID \(place.placeID)")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment