Reputation: 12477
I'm using a custom Icon in my application for the user's current location, and want to keep it this way while upgrading to the new Google Maps library.
With the Google Maps v1 library, i extended MyLocationOverlay and overwritten the drawMyLocation method to draw my custom icon in there.
The GoogleMap enables the current location with the setMyLocationEnabled method, but there's no way to customize it, as far as i know.
Does anybody know how to accomplish this on v2 ?
Upvotes: 17
Views: 22118
Reputation: 2645
Create a Marker in the map constructor that uses a custom icon.
_myLocation = mMap.addMarker(new MarkerOptions()
.position(MAP_CENTER)
.title("My Location")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.mylocation)));
Implement a Location Changed Listener, https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/LocationSource.OnLocationChangedListener
Update the Marker Location when the Provider is called:
public void onLocationChanged (Location location)
{
_myLocation.position(location); //May have to convert from location to LatLng
}
Upvotes: 14
Reputation: 12477
Ok, so i just figured that if you don't add the title or snippet, the marker will not have effect on a click event, and it acts as an image overlay. Even though it's not perfect, it suits my needs
private Marker marker = mMap.addMarker(new MarkerOptions()
.position( latLng)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));
Thanks everyone
Upvotes: 6
Reputation: 23638
There is definitely a way to show custom icon on current location. Checkout Link you will get more idea to customize your icon on map.
Try out the code below :
private static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298);
private Marker melbourne = mMap.addMarker(new MarkerOptions()
.position(MELBOURNE)
.title("Melbourne")
.snippet("Population: 4,137,400")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));
Upvotes: 0