Remove default user location icon

I am developing an app using Google Maps v2 for Android and I was able to place a custom icon at the user position, but I cannot remove it by default, so it overlays its custom icon like in the image:

enter image description here

(It's that simple: p)

My code is like:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);

    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    map.setMyLocationEnabled(true);

    map.setOnMyLocationChangeListener(new OnMyLocationChangeListener() {

        @Override
        public void onMyLocationChange(Location location) {
            if (location == null)
                return;

            mPositionMarker = map.addMarker(new MarkerOptions()
            .flat(true)
            .icon(BitmapDescriptorFactory
                    .fromResource(R.drawable.logop1))
            .anchor(0.5f, 1f)
            .position(new LatLng(location.getLatitude(), location.getLongitude())));

        }
    });
}

      

So: 1) Is there a way to remove the default blue dot of the user's current current location?

2) Will there be an update to the user's location when I go to the "real world" (I can't validate it for expediency reasons), or do I need to write / override a method to update the user's position?

Thank you in advance

+3


source to share


3 answers


Thanks to joao2fast4u (lol) and แนแพถฦ”ฦลˆ ใƒ„. I followed your recommendations and I managed to get it to work. Since I haven't seen an answer to this problem, I am posting my solution here:



package com.onsoftwares.ufvquest;
import android.location.Location;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapActivity extends ActionBarActivity implements LocationListener, GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener  {

private GoogleMap map;
private Marker mPositionMarker;
private LocationClient mLocationClient;
private LocationRequest mLocationRequest;
private LatLng mLatLng;

private boolean mUpdatesRequested = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);

    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    mLocationClient = new LocationClient(this, this, this);

    mLocationRequest = LocationRequest.create();

    mLocationRequest.setInterval(5000);

    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    // Set the interval ceiling to one minute
    mLocationRequest.setFastestInterval(1000);

    // Note that location updates are off until the user turns them on
    mUpdatesRequested = false;
}

@Override
protected void onStart() {
    super.onStart();
    mLocationClient.connect();
};

@Override
protected void onStop() {
    if (mLocationClient.isConnected()) {
        mLocationClient.removeLocationUpdates(this);
        mLocationClient.disconnect();
    }
    super.onStop();
};

@Override
public void onConnectionFailed(ConnectionResult arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onConnected(Bundle arg0) {
    mLocationClient.requestLocationUpdates(mLocationRequest, this);
}

@Override
public void onDisconnected() {
    // TODO Auto-generated method stub

}

@Override
public void onLocationChanged(Location location) {
    // Get the current location
    Location currentLocation = mLocationClient.getLastLocation();

    // Display the current location in the UI
    if (currentLocation != null) {
        LatLng currentLatLng = new LatLng (currentLocation.getLatitude(), currentLocation.getLongitude());
        if (mPositionMarker == null) {
            mPositionMarker = map.addMarker(new MarkerOptions()
                            .position(currentLatLng)
                            .title("Eu")
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.male_user_marker)));
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 15));
        } else
            mPositionMarker.setPosition(currentLatLng);
    }
}
}

      

+3


source


You will need to discontinue use GoogleMap.setMyLocationEnabled

and write a little more code, including having your own LocationClient

and adding Circle

for precision.

You have to do it yourself. - set to falsegmaps.getUiSettings().setMyLocationButtonEnabled(false);



  • create your own location button
  • if you get your current location, set the marker with the icon on this
  • if you press your location button, move the camera and center it on the map.

This will remove the blue dot

+5


source


map.setMyLocationEnabled (true); delete line

+4


source







All Articles