在Android里完美实现基站和WIFI定位(5)
如果还想同时使用GPS定位,其实也很简单,可以和FourSquare提供的BestLocationListener结合起来,将上面那段代码添加到BestLocationListener的register方法里: public v
如果还想同时使用GPS定位,其实也很简单,可以和FourSquare提供的BestLocationListener结合起来,将上面那段代码添加到BestLocationListener的register方法里:
public void register(LocationManager locationManager, boolean gps, Context context) {
if (DEBUG) Log.d(TAG, "Registering this location listener: " + this.toString());
long updateMinTime = SLOW_LOCATION_UPDATE_MIN_TIME;
long updateMinDistance = SLOW_LOCATION_UPDATE_MIN_DISTANCE;
if (gps) {
updateMinTime = LOCATION_UPDATE_MIN_TIME;
updateMinDistance = LOCATION_UPDATE_MIN_DISTANCE;
}
List<String> providers = locationManager.getProviders(true);
int providersCount = providers.size();
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
setChanged();
notifyObservers(null);
}
for (int i = 0; i < providersCount; i++) {
String providerName = providers.get(i);
if (locationManager.isProviderEnabled(providerName)) {
updateLocation(locationManager.getLastKnownLocation(providerName));
}
// Only register with GPS if we've explicitly allowed it.
if (gps || !LocationManager.GPS_PROVIDER.equals(providerName)) {
locationManager.requestLocationUpdates(providerName, updateMinTime,
updateMinDistance, this);
}
}
if(cellLocationManager == null) {
CellInfoManager cellManager = new CellInfoManager(context);
WifiInfoManager wifiManager = new WifiInfoManager(context);
cellLocationManager = new CellLocationManager(context, cellManager, wifiManager) {
@Override
public void onLocationChanged() {
if ((latitude() == 0.0D) || (longitude() == 0.0D)) return;
Location result = new Location("CellLocationManager");
result.setLatitude(latitude());
result.setLongitude(longitude());
result.setAccuracy(accuracy());
onBestLocationChanged(result);
this.stop();
}
};
}
//cellLocationManager.stop();
cellLocationManager.start();
// LocationController controller = LocationController.requestLocationUpdates("", updateMinTime,updateMinDistance, this, context);
// controller.requestCurrentLocation();
}
精彩图集
精彩文章





