问题
I am creating an small application in Android, which points the current location. I have used GPS-provider for that, but found out that I won't get the data using GPS-provider at some places.
Can any one help me in getting this?
回答1:
If you are connected to WIFI then simply use NETWORK PROVIDER for your location updates. they will be fast and enough accurate too.
generally if location updates are not required so frequently then location updates are asked from both GPS and NETWORK together at the same time. whenever you get a location update of desired accuracy unregister from listening location updates.
But if location updates are required frequently then calling GPS can be a KILLER OF BATTERY too so be careful of using GPS PROVIDER.
GPS Updates are available good under open sky only. GPS Updates takes time , takes battery but Are More Accurate.
Network Updates are quicker, consumes less battery but are comparatively less accurate. But if we are talking about a WIFI accuracy it will be near to 50 or 100 that can serve many real time requirement.
It all depends on your requirement.
回答2:
To check if the device is connected via mobile or wifi you can use this code:
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
//wifi
State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
Then use like this...
if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
//wifi
}
for more info see link
来源:https://stackoverflow.com/questions/10172831/get-location-details-using-wifi