【发布时间】:2013-01-26 00:00:29
【问题描述】:
我在我的 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);
}
【问题讨论】:
-
您是否使用 MapView 来显示用户位置?
-
我正在使用 Google Maps Android API v2。