Reputation: 2538
I'm drawing a bit of a blank, I want to hide the blue location dot from the Google Maps iOS API. But if I set
self.mapView.myLocationEnabled = false
Then all location services are halted. I only need to temporarily disable the blue dot, is there a way to make it clear while continuing to update locations in the background?
Upvotes: 2
Views: 4789
Reputation: 539
do this right after you have initialised your mapView
mapView.settings.myLocationButton = false
Upvotes: 2
Reputation: 1
Configure Camera Position
let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: 48.857165, longitude: 2.354613, zoom: 8.0)
viewMap.camera = camera
viewMap.delegate = self
Initialize circle with radius 0
let circle = GMSCircle.init(position: camera.target, radius: 0)
circle.fillColor = UIColor.clear
circle.map = viewMap
Upvotes: -1
Reputation: 1247
I tested the same, i added below line of code into my application and displayed the user location in Google maps.
mapView.myLocationEnabled=YES;
If i totally remove the above line of code, it displays all other annotations and does not show the user location
Upvotes: 2
Reputation: 257
Took me awhile but I think I got it working.
In your viewDidLoad():
// MARK: Location Settings
// Location Manager
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
mapView.delegate = self
mapView.settings.myLocationButton = true
}
You need this bit of code to assign the delegates and to start the updating of location. This will also add the location button to the google map. You will also have to make sure you add the authorization message into the info.plist.
{key=NSLocationWhenInUseUsageDescription}: {type=String}: {value=custom message}
.
And then you will need to extend these delegates (place them at the bottom of your MapViewController outside your class):
// MARK: - Extension: LocationManager
extension MapViewController: CLLocationManagerDelegate {
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedWhenInUse {
locationManager.startUpdatingLocation()
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
locationManager.stopUpdatingLocation()
}
}
}
// MARK: - Extension: GMSMapView
extension MapViewController: GMSMapViewDelegate {
func didTapMyLocationButtonForMapView(mapView: GMSMapView) -> Bool {
locationManager.updateLocation()
return false
}
}
CLocationManagerDelegate:
GMSMapViewDelegate:
Upvotes: 0