Google Maps Location - Hide Blue dot (Current Location Marker) and Show My Location Button
The location button is only visible when the My Location
layer is enabled with the setMyLocationEnabled
method. You can simulate this behavior by adding a similar button of your own that will center on the user's location when it is pressed.
Remove blue dot indicator (my location) from Google Maps in Flutter
You can set the myLocationEnabled
property to false in the GoogleMap
widget
How to replace or remove the circle around my location blue dot for Google Maps
The blue circle should be removed with
map.setMyLocationEnabled(false);
Android Make Disappear or remove the blue dot on the map v2
If you want to have "google's go-to-my-location-button" you have to have "google's blue dot". If you don't want "google's blue dot" you also will not have "google's go-to-my-location-button" and thus you'll have to implement it by yourself. Just add requestLocationUpdates (GoogleApiClient client, LocationRequest request, LocationListener listener) to track user location and add your custom "go-to-my-location-button" on top of map.
How to delete blue dot in android google map?
Use this location tracker
public class PlayServicesLocationTracker implements ConnectionCallbacks, OnConnectionFailedListener, LocationListener {
// Google client to interact with Google API
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
private Context mContext;
private OnLocationFetchListener mListener;
public PlayServicesLocationTracker(Activity context) {
this.mContext = context;
if (checkPlayServices()) {
buildGoogleApiClient();
createLocationRequest();
checkLocationEnabled(context);
onStart();
}
}
public PlayServicesLocationTracker(Context context) {
this.mContext = context;
if (checkPlayServices()) {
buildGoogleApiClient();
createLocationRequest();
onStart();
}
}
/**
* Method used to set Location listener
*
* @param listener
*/
public void setLocationListener(OnLocationFetchListener listener) {
mListener = listener;
}
public void onStart() {
if (mGoogleApiClient != null) {
mGoogleApiClient.connect();
}
}
public void onStop() {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
stopLocationUpdates();
}
}
/**
* Method to display the location on UI
*/
private void displayLocation() {
Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (lastLocation != null) {
if (mListener != null)
mListener.onLocationChanged(lastLocation);
}
}
/**
* Creating google api client object
*/
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(mContext)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API).build();
}
/**
* Creating location request object
*/
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(10000);
mLocationRequest.setFastestInterval(5000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setSmallestDisplacement(10);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setSpeedRequired(true);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
}
/**
* Method to verify google play services on the device
*/
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext);
if (resultCode != ConnectionResult.SUCCESS) {
Toast.makeText(mContext, "This device is not supported.", Toast.LENGTH_LONG).show();
return false;
}
return true;
}
/**
* Starting the location updates
*/
protected void startLocationUpdates() {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
}
/**
* Stopping location updates
*/
protected void stopLocationUpdates() {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected())
LocationServices.FusedLocationApi.removeLocationUpdates(
mGoogleApiClient, this);
}
@Override
public void onConnectionFailed(ConnectionResult result) {
}
@Override
public void onConnected(Bundle arg0) {
displayLocation();
startLocationUpdates();
}
@Override
public void onConnectionSuspended(int arg0) {
mGoogleApiClient.connect();
}
@Override
public void onLocationChanged(Location location) {
//Toast.makeText(mContext, "Got location", Toast.LENGTH_SHORT).show();
displayLocation();
}
public void checkLocationEnabled(final Activity activity) {
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true);
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// All location settings are satisfied. The client can initialize location
// requests here.
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Location settings are not satisfied. But could be fixed by showing the user
// a dialog.
try {
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
status.startResolutionForResult(
activity,
MenuActivity.LOCATION_DIALOG_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
// Ignore the error.
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Location settings are not satisfied. However, we have no way to fix the
// settings so we won't show the dialog.
break;
}
}
});
}
public interface OnLocationFetchListener {
void onLocationChanged(Location location);
}}
Related Topics
Wkwebview Origin Null Is Not Allowed by Access-Control-Allow-Origin
How to Exit Iphone Application
How to Rotate a Uiimage 90 Degrees
Seeing Black Bars At the Top and Bottom of the Iphone X Simulator
How to Scroll List Programmatically in Swiftui
Importing Commoncrypto in a Swift Framework
Find Out If Character in String Is Emoji
Ios 7 - Status Bar Overlaps the View
Can't Get Correct Value of Keyboard Height in Ios8
Detect Tap on a Button in Uitableviewcell for Uitableview Containing Multiple Sections
What's the Difference Between the Atomic and Nonatomic Attributes
How to Share Data Between View Controllers and Other Objects in Swift
Array Extension to Remove Object by Value
Fatal Error: Unexpectedly Found Nil While Unwrapping an Optional Values