Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize Google Maps blue dot for current location

I'm using a 2013 version of Google Maps SDK for iOS. I would like to customize the default blue dot for current location with another icon or pulsing circles around.

I know we can do that with mapView:viewForAnnotation: in MKMapView, but I can't found out how to do it with Google Maps.

like image 947
Nicolas Roy Avatar asked Aug 20 '13 09:08

Nicolas Roy


2 Answers

For Swift 4.0

When you set up your GMSMapView:

mapView.isMyLocationEnabled = false

And when user location is updated:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let userLocationMarker = GMSMarker(position: location.coordinate)
    userLocationMarker.icon = UIImage(named: "yourImageName")
    userLocationMarker.map = mapView   
}
like image 175
George Leonidas Avatar answered Sep 27 '22 22:09

George Leonidas


There is no way to do this with current version of the SDK (1.4.3), and actually there is an open issue with this request: Look here.

As a work around, 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 the position of it using a CLLocationManager, so it always show the current position. It's a bit tricky but is the only way, I could think, that you can achieve this. If you need a more complete example let me know.

like image 23
JP Illanes Avatar answered Sep 27 '22 21:09

JP Illanes