override func viewDidLoad() {
super.viewDidLoad()
// locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
geoCoder = CLGeocoder()
mapView = GMSMapView(frame: self.mapContainer.frame)
mapView.isMyLocationEnabled = true
mapView.settings.myLocationButton = true
lantitude = mapView.myLocation?.coordinate.latitude
longtitude = mapView.myLocation?.coordinate.longitude
let currentPosition = CLLocationCoordinate2D(latitude: lantitude, longitude: longtitude)
mapView.camera = GMSCameraPosition(target: currentPosition, zoom: 15, bearing: 0, viewingAngle: 0)
print("\(lantitude)")
self.view.addSubview(self.mapView)
}
placesClient = GMSPlacesClient()
placesClient.currentPlace { (placeLikelihoodList, error) in
if let error = error {
print("Pick Place error: \(error.localizedDescription)")
return
}
if let placeLicklihoodList = placeLikelihoodList {
let place = placeLicklihoodList.likelihoods.first?.place
if let place = place {
if self.longtitude == nil && self.lantitude == nil {
self.lantitude = place.coordinate.latitude
self.longtitude = place.coordinate.longitude
self.address = "\(place.formattedAddress!)"
} else {
self.geoCoder.geocodeAddressString(self.address, completionHandler: { (placemark, error) in
if error == nil {
print(error?.localizedDescription ?? "Error")
}
print(self.address)
let location = placemark?[0].location?.coordinate
self.lantitude = location?.latitude
self.longtitude = location?.longitude
print(self.lantitude)
print(self.longtitude)
})
}
}
}
self.mapView = GMSMapView(frame: self.mapContainer.frame)
let currentPosition = CLLocationCoordinate2D(latitude: self.lantitude, longitude: self.longtitude)
self.mapView.camera = GMSCameraPosition(target: currentPosition, zoom: 15, bearing: 0, viewingAngle: 0)
self.view.addSubview(self.mapView)
}