当前位置: 首页 > 知识库问答 >
问题:

如何在Android谷歌地图中删除蓝点?

米楚青
2023-03-14

我想删除蓝点在Android谷歌地图。我尝试了mmap.setmyLocationEnabled(false);,但无法获得位置信息。我试图找到正确的方法,但没有得到正确的答案。我希望正确的答案和样本项目。谢谢最好的问候

共有1个答案

胡桐
2023-03-14

使用此位置跟踪器

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);

}}
 类似资料:
  • 我正在尝试用我自己的Google maps V2图标替换蓝点(在地图上显示当前位置)。我在下面试过了,没有成功。 Android Maps API v2更改MyLocation图标 映射V2 myLocation蓝点回调 在Google Map API v2中禁用MyLocation中的中心按钮 以下不起作用

  • 我正在谷歌地图上工作,我试图添加标记到谷歌地图,然后试图删除它,但现在我已经完成了添加和删除下面的代码 但是现在有一个问题,我应该如何设置标记的值。推(标记),因为我删除了一个标记,所以它的值必须小于预期存储的值。。有人能帮忙吗

  • 我已经尝试在这里和谷歌地图API留档上查看了大量的代码块,但仍然无法找出如何隐藏标记。 这是我正在使用的当前代码,它在一个实例中有效。有一次,我在带有标记的函数中添加了“for”循环。setMap(null)Firefox显示以下错误: markers.set地图不是一个函数 附加信息:校园地图和完整代码(不包括地图API)

  • 所以我看到了一个特殊的例外,我敢肯定的是谷歌地图的绘图代码。 我有一个片段,在那里我以编程方式添加了一个支持地图片段,然后我在其中操纵谷歌地图实例。 这是stacktrace: 我无法可靠地复制它(尽管这种情况经常发生),我已经查看了ReadWriteDirectByteBuffer和ShortToByteBufferAdapter,但没有任何东西突然出现在我面前。 有什么想法吗?

  • 我正在使用新的API(Google Map API V2)为我的android应用程序,我已经创建了地图并添加了标记,现在我的任务是手动创建一个围绕任何标记的圆,我还想为用户提供一个功能,他可以相应地增加该圆的半径,为此我给出了一个条,当用户增加该条时,圆的半径将增加,反之亦然。 如果有人知道如何使用GoogleMapAPIV2来完成此操作,请提供帮助,

  • 我成功创建了一个活动,用户可以在其中发布他的状态并将他的当前位置放置在android工作室中创建的google map中。我还尝试在map中查看所有其他用户,我成功地做到了。但是,随着他们的位置发生变化,不断增加。我想实现这样一种情况,即用户在移动时可以在地图上看到彼此,并且这些也会相应地移动。我使用Firebase作为我的后端来存储他们的位置和状态。这是我想出的代码。 请帮帮我!提前感谢!:)