灵敏度 Android 位置传感器
Posted
技术标签:
【中文标题】灵敏度 Android 位置传感器【英文标题】:Sensitivity Android Location Sensor 【发布时间】:2016-12-15 10:45:45 【问题描述】:我想每 10 毫秒获取一次位置,但我的位置会在大约 30 秒或 40 秒内发生变化。我的错在哪里?有人帮助我吗?我正在使用这个代码块。我也用过,但我遇到了一些问题http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/
@Override
protected void onStart()
super.onStart();
mGoogleApiClient.connect();
@Override
protected void onDestroy()
super.onDestroy();
mGoogleApiClient.disconnect();
synchronized void buildGoogleApiClient()
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
@Override
public void onConnected(Bundle bundle)
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(1); // Update location every second
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
return;
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null)
lat = String.valueOf(mLastLocation.getLatitude());
lon = String.valueOf(mLastLocation.getLongitude());
@Override
public void onConnectionSuspended(int i)
@Override
public void onLocationChanged(Location location)
mLastLocation = location;
Toast.makeText(MainActivity.this, location.getLatitude()+"+-+"+location.getLongitude(), Toast.LENGTH_SHORT).show();
updateUI();
@Override
public void onConnectionFailed(ConnectionResult connectionResult)
buildGoogleApiClient();
void updateUI()
Log.e("Updated",lat+"---"+lon);
Android 版本 6.0.1
【问题讨论】:
【参考方案1】:你可以这样做:
mLocationRequest.setInterval(3000);
mLocationRequest.setFastestInterval(1000); // For 1 Second = 1000 millis
【讨论】:
它不起作用:/我再次每 40-50 秒获取一次位置。以上是关于灵敏度 Android 位置传感器的主要内容,如果未能解决你的问题,请参考以下文章