Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google Maps V2 change My Location Icon

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 ?

like image 840
Robert Estivill Avatar asked Dec 12 '12 17:12

Robert Estivill


People also ask

Where is the My Location icon in Google Maps?

Mobile. Open Google Maps on your phone or tablet. It's the map icon with a "G" at its top-left corner, and you'll find it on one of the home screens (iPhone/iPad) or in the app drawer (Android). If you haven't enabled Location Services, follow the on-screen instructions to do so when prompted.


2 Answers

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
}
like image 176
javram Avatar answered Oct 05 '22 23:10

javram


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

like image 32
Robert Estivill Avatar answered Oct 06 '22 00:10

Robert Estivill