0
votes

I'm using com.google.android.gms.maps.MapView and i want to hide the current location "marker" (the blue one on the next picture)

enter image description here

The red one is my marker for current location and i would like to be placed on the center of my location, now is placed like it would be an arrow pointing down. Do you know how can i do this?

EDIT: I think that there is enough to place my marker over the blue one, and it will cover it. How can i do that?

I'm placeing my marker like that :

currentPositionMarker = googleMap.addMarker(new MarkerOptions().position(location).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin)));

2

2 Answers

1
votes

You can set the anchor point for the marker image:

currentPositionMarker = 
    googleMap.addMarker(
        new MarkerOptions()
            .position(location)
            .anchor(0.5f, 0.5f)
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.pin)));

You can hide the my location layer doing

googleMap.setMyLocationEnabled(false);
0
votes

You need to do this: view_custom_marker.xml

 <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_marker_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/marker_mask">

<ImageView
    android:id="@+id/profile_image"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_gravity="center_horizontal"
    android:contentDescription="@null"
    android:src="@drawable/avatar" />
 </FrameLayout>

Convert this view into bitmap by using the code below

    private Bitmap getMarkerBitmapFromView(@DrawableRes int resId) {

    View customMarkerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.view_custom_marker, null);
    ImageView markerImageView = (ImageView) customMarkerView.findViewById(R.id.profile_image);
    markerImageView.setImageResource(resId);
    customMarkerView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    customMarkerView.layout(0, 0, customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight());
    customMarkerView.buildDrawingCache();
    Bitmap returnedBitmap = Bitmap.createBitmap(customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    canvas.drawColor(Color.WHITE, PorterDuff.Mode.SRC_IN);
    Drawable drawable = customMarkerView.getBackground();
    if (drawable != null)
        drawable.draw(canvas);
    customMarkerView.draw(canvas);
    return returnedBitmap;
}
}

Add your custom marker in on Map ready callback.

@Override
public void onMapReady(GoogleMap googleMap) {
Log.d(TAG, "onMapReady() called with");
mGoogleMap = googleMap;
MapsInitializer.initialize(this);
addCustomMarker();
}
private void addCustomMarker() {
Log.d(TAG, "addCustomMarker()");
if (mGoogleMap == null) {
    return;
}

// adding a marker on map with image from  drawable
mGoogleMap.addMarker(new MarkerOptions()
.position(mDummyLatLng).icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmapFromView(R.drawable.avatar))));
}