10

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.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Nicolas Roy
  • 3,773
  • 5
  • 27
  • 42

3 Answers3

16

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.

JP Illanes
  • 3,665
  • 39
  • 56
  • Ya,I tried it but it is displaying more than one markers around users current location. Please give a more elaborate code. – G.Abhisek Jan 18 '16 at 05:26
  • Sorry, I haven't used Gmaps for a long time now, I am not sure if this answer is still valid. Anyway, if you have an issue, please ask a new question, I can't help you with your issue modifying an old answer. – JP Illanes Jan 18 '16 at 09:15
  • Thanks for your answer. It helps me a lot. – Mihir Oza Jan 28 '16 at 14:29
4

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   
}
rmtheis
  • 5,992
  • 12
  • 61
  • 78
3

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 =  lastLocation.coordinate    
    }

}

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

Valeriy Van
  • 1,851
  • 16
  • 19
trndjc
  • 11,654
  • 3
  • 38
  • 51
  • currentLocationMarker?.icon = UIImage(named: "driver_circle")!.withAlignmentRectInsets(UIEdgeInsets(top: 0, left: 0, bottom: UIImage(named: "driver_circle")!.size.height/2, right: 0)) A quick fix which took me days to understand! – shanezzar Dec 24 '18 at 16:30