How to get Location with Wifi in Android?

三世轮回 提交于 2019-11-30 21:25:13

Say, can I setup "request Location Update" for GPS_PROVIDER and NETWORK_PROVIDER (or PASSIVE_PROVIDER) to same function call like this:

// SETUP Location Manager
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, this);

In this case, I get only GPS data.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!