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 ?
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.
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
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With