Set the blue dot of Google Maps for your current location

I am using the Google Maps SDK version for iOS in 2013. I would like to set the default blue dot for the current location using a different icon or pulsating circles around.

I know that we can do this using mapView:viewForAnnotation: in MKMapView, but I cannot find out how to do this with Google Maps.

+7
ios google-maps google-maps-sdk-ios google-maps-markers currentlocation
source share
2 answers

It is not possible to do this with the current version of the SDK (1.4.3), and there is actually an open problem with this request: Look here .

As a job, you can hide the default button with:

  _map.myLocationEnabled = NO; 

Then create a custom GMSMarker

  GMSMarker *pointMarker = [GMSMarker markerWithPosition:currentPosition]; pointMarker.icon = [UIImage imageNamed:@"YourImage"]; pointMarker.map = _map; 

And change its position using the CLLocationManager so that it always shows the current position. This is a little complicated, but this is the only way I could think that you can achieve this. If you need a more complete example, let me know.

+11
source share

Swift 4

 class MasterMapViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate { let currentLocationMarker = GMSMarker() override func viewDidLoad() { super.viewDidLoad() addCurrentLocationMarker() } func addCurrentLocationMarker() { let currentLocationMarkerView = UIView() currentLocationMarkerView.frame.size = CGSize(width: 40, height: 40) currentLocationMarkerView.layer.cornerRadius = 40 / 4 currentLocationMarkerView.clipsToBounds = true let currentLocationMarkerImageView = UIImageView(frame: currentLocationMarkerView.bounds) currentLocationMarkerImageView.contentMode = .scaleAspectFill currentLocationMarkerImageView.image = UIImage(named: "masterAvatar") currentLocationMarkerView.addSubview(currentLocationMarkerImageView) currentLocationMarker.iconView = currentLocationMarkerView currentLocationMarker.isTappable = false currentLocationMarker.map = mapView } // location manager delegate func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { let lastLocation = locations.last! currentLocationMarker.position = CLLocationCoordinate2D(latitude: lastLocation.coordinate.latitude, longitude: lastLocation.coordinate.longitude) } } 

Use this only as a starting point! This is not an attractive alternative, because the constant updating of the marker position on the map occurs with a performance hit. If you want to go this route, find a way to not constantly update the marker position from a location manager delegate.

+2
source share

All Articles