문제

My application requires current location of the user. For this I have implemented the code and I am able to get the current location. The code tries to get the best provider first and then fetches location information. The problem is that the current location is returned from NETWORK_PROVIDER if GPS_PROVIDER is disabled. If both NETWORK_PROVIDER and GPS_PROVIDER are enabled then the best provider will be GPS_PROVIDER and this takes too much time to get the current location.

So, is it alright if we set the location provider as NETWORK_PROVIDER only so that it will not matter whether GPS_PROVIDER is enabled or not.

Please let me know what is the right approach.

Regards

Sunil

도움이 되었습니까?

해결책

Depending on your application, you might be able to use just the network location. This is fine-grained enough for many location-based services. Plus you don't have to worry about sucking up the user's battery with GPS radio.

But if you really want as accurate a location as possible, why not listen to both providers? You could use the getLastKnownLocation() method for the initial location. Then you can use the NETWORK_PROVIDER location. Then, as soon as you get a fix from the GPS_PROVIDER, you can ignore or remove the network listener.

다른 팁

GPS gives better precision than Network provider.

Network provider is done using triangulation of cell towers and wifi.

So, if you need immediately, start with "last known location" then switch to network, once you have the fix from the gps, start using it.

regards, vinay

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top