首页 文章

android谷歌 Map :如何只使用GPS?

提问于
浏览
1

我需要更高的准确性,以获得Android使用网络和wifi或GPS的位置,我需要它使用只有GPS的最精确的位置 .

我正在 Build 一个简单的应用程序来跟踪手机,该应用程序炒得很好但我的问题是,即使在我的手机上启用GPS并要求高精度 setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); ,该应用程序使用wifi和网络来确定我的位置而不是GPS . 我怎么能让它只使用GPS?

在清单中

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

我的代码的一部分..

public class MainActivity extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener, LocationListener {

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate ...
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();
    createMapView();
}

@Override
public void onConnected(Bundle bundle) {

    mLocationRequest = LocationRequest.create();
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    mLocationRequest.setInterval(1000); // Update location every second

    LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);
}

1 回答

  • 0

    更改位置请求优先级

    mLocationRequest = LocationRequest.create();
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    

    这会对你有所帮助

相关问题