Reputation: 275
I have followed the steps in tutorials how to get user's location via Google Maps SDK. I used the tutorial provided by Google also by Ray Wenderlich but it's no use. The location button doesn't even show.
Any help would be great, thanks. Here's my code:
class NearestDealerViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var mainMenuLabel: UILabel!
@IBOutlet weak var nearestDealer: UILabel!
@IBOutlet weak var mapView: GMSMapView!
let locationManager = CLLocationManager()
let transitionDelegate = TransitionDelegate()
var delegate: NearestDealerViewControllerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
println(mapView.myLocationEnabled)
}
func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedWhenInUse {
locationManager.startUpdatingLocation()
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
}
println(mapView.myLocationEnabled)
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
if let location = locations.first as? CLLocation {
mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
locationManager.stopUpdatingLocation()
}
}
@IBAction func backTapped(sender: AnyObject) {
delegate?.dismissNearestDealerViewController()
}
}
Upvotes: 0
Views: 469
Reputation: 3225
You should put in the viewDidLoad() next line of code:
mapView.isMyLocationEnabled = true
Upvotes: 1