Created
October 29, 2015 21:40
-
-
Save ziyang0621/b016214c5e689b88299f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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