如何在Android Google Map中删除蓝点? [英] How to delete blue dot in android google map?
本文介绍了如何在Android Google Map中删除蓝点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Android Google地图中删除蓝点.
我尝试了mMap.setMyLocationEnabled(false);
但我无法获取位置信息.
我试图找到正确的方法,但是没有得到正确的答案.
我希望正确的答案和示例项目.
谢谢
最好的问候
I'd like to delete blue dot in android google map.
I tried mMap.setMyLocationEnabled(false);
but I cannot get location information.
I tried to find correct way, but did not get correct answer.
I hope correct answer and sample project.
Thanks
Best regards
推荐答案
使用此位置跟踪器
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);
}}
这篇关于如何在Android Google Map中删除蓝点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文