Android Maps API v2 Change MyLocation Icon

Gyroscope picture Gyroscope · Feb 12, 2013 · Viewed 62.1k times · Source

I would like to replace the default icon that Android Maps V2 uses for 'My Location' (The little blue dot/arrow) with my own image. I've created my own tile provider that brings in a few maps which are predominantly blue and as such the default My Location icon is very hard to see. Previously I would have just overridden the draw method of the MyLocationOverlay, but there doesn't seem to be one in the new api. Any help would be great!

EDIT: I also need the icon to be able to rotate, the same way that the arrow does depending on which way you are facing. So i can't just use a normal marker :( Basically I just need to create a custom image for that arrow..

enter image description here

Update Hi All, the update to Google play now allows flat markers and marker rotation which is exactly what I needed.

Answer

Intathep picture Intathep · Feb 12, 2013

my simple solution way is just disable "my location" of Google map

and create ImageView on Map with my icon then capture ImageView with

onClick and getMyLocation , animateCamera in onClick

 this.mGoogleMap.getUiSettings().setMyLocationButtonEnabled(false);
 this.mGoogleMap.setMyLocationEnabled(true);

.

@Override
public void onClick(final View v) {

    Location location = this.mGoogleMap.getMyLocation();

        if (location != null) {

            LatLng target = new LatLng(location.getLatitude(), location.getLongitude());
            CameraPosition position = this.mGoogleMap.getCameraPosition();

            Builder builder = new CameraPosition.Builder();
            builder.zoom(15);
            builder.target(target);

            this.mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(builder.build()));

          }    
}