开发者

how to change provider Gps to Network for geo location?

I am working on geolocation application in that I want to use Gps provider as it giving accurate location than network provider.B开发者_JS百科ut sometimes indoor the gps signal is not reaching then I want to use network provider.Whenever Gps signal is not reaching that time I want to use network provider.How can I switch between these providers?

Thanks, Vishakha.


If you have a button that switches a variable on or off, you can switch between providers like this (Sorry that it's pseudo code).

if (GPSisOff){
   LocationProvider locationProvider = LocationManager.NETWORK_PROVIDER;
} else {
   LocationProvider locationProvider = LocationManager.GPS_PROVIDER;
}

Also it depends on whether you want it to detect automatically. If that's the case, you might want to check the location return from your current locationProvider(whether it's GPS or Network) and determine how accurate it is and switch accordingly.


Check out the samples at http://developer.android.com/guide/topics/location/obtaining-user-location.html.

Your locationListener is notified if a location provider is not available at the moment with the onStatusChanged method.


Another thing you can do is to use the same LocationListener for both gps and network providers. So, instead of using only gps, or only network, you can enable both, so that your app's LocationListener will receive location updates from both providers (or from the only one that is available, if the other is not able to provide updates).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜