Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One possible workaround might be drawing a <code>Marker</code> (with a similar icon) on top of the My Location dot so you can receive the corresponding <code>onMarkerClick()</code> callback. This would also require removing the marker and adding it to the new location everytime there's a location update event, which you can listen to by implementing <code>OnMyLocationChangeListener</code>.</p> <p><strong>EDIT</strong>: the <code>OnMyLocationChangeListener</code> interface is now deprecated, one should use instead the new <a href="https://developer.android.com/reference/com/google/android/gms/location/LocationClient.html" rel="nofollow"><code>LocationClient</code></a> and the associated <a href="https://developer.android.com/reference/com/google/android/gms/location/LocationListener.html" rel="nofollow"><code>LocationListener</code></a>.</p> <p>So the relevant code could look something like this (I hadn't actually tested this):</p> <pre><code>public class DemoMapFragment extends SupportMapFragment implements OnMyLocationChangeListener, OnMarkerClickListener { // Note that 'mMap' may be null if the Google Play services APK is not available. private GoogleMap mMap; private Marker myLocationMarker; private static BitmapDescriptor markerIconBitmapDescriptor; /* ... */ @Override public void onResume() { super.onResume(); setUpMapIfNeeded(); // Get a reference to the map mMap.setMyLocationEnabled(true); // Enable the my-location layer mMap.setOnMyLocationChangeListener(this); mMap.setOnMarkerClickListener(this); } private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { mMap = getMap(); // Check if we were successful in obtaining the map. if (mMap != null) { // The Map is verified. It is now safe to manipulate the map: // Load custom marker icon markerIconBitmapDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.my_location_dot_icon); // When the map is first loaded we need to add our marker on top of My Location dot myLocationMarker = mMap.addMarker(new MarkerOptions() .position(new LatLng(mMap.getMyLocation().getLatitude(),mMap.getMyLocation().getLongitude())) .icon(markerIconBitmapDescriptor)); // Set default zoom mMap.moveCamera(CameraUpdateFactory.zoomTo(15f)); } } } @Override public void onMyLocationChange(Location location) { // Remove the old marker object myLocationMarker.remove(); // Add a new marker object at the new (My Location dot) location myLocationMarker = mMap.addMarker(new MarkerOptions() .position(new LatLng(location().getLatitude(),location().getLongitude())) .icon(markerIconBitmapDescriptor)); } @Override public boolean onMarkerClick(Marker marker) { if (marker.equals(myLocationMarker)) { /* My Location dot callback ... */ } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload