开发者

Should I use separate locationManager for GPS and Network Provider?

Can I use the s开发者_开发知识库ame locationManager for requesting updates for the gps and network provider, or should I create two locationManagers and separate onLocation changed functions etc. I got really confused about this


You will want to check and see which one is available in the order you want to use them and then use the corresponding one:

if(mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, LOCATION_UPDATE_MIN_TIME, LOCATION_UPDATE_MIN_DISTANCE, locationListener);
}
else if(mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
    mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_UPDATE_MIN_TIME, LOCATION_UPDATE_MIN_DISTANCE, locationListener);
}

You can use the same listener because all the listener's methods take as a parameter a Location object which is source agnostic:

@Override
public void onLocationChanged(Location location) {
    // updateLocation();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜