我在我的 Fragment 类中实现 LocationListener 并使用以下代码来跟踪位置更新,尽管它没有得到应有的频繁更新。我需要在 Google Navigator 等地图上显示用户位置。
寻找最佳供应商
mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
// if I uncomment the next line, it takes too long to get the location
// criteria.setAccuracy(Criteria.ACCURACY_FINE);
// if I leave the line above commented, the app seems to receiving location from triangulation
mProvider = mLocationManager.getBestProvider(criteria, false);
Location location = mLocationManager.getLastKnowLocation(mProvider);
LocationChanged 事件
@Override
public void onLocationChanged(Location location) {
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
setMapCameraPosition(latLng);
}