Android wifibased localization Localization types Android allows location
Android wifi-based localization
Localization types • Android allows (location providers) – GPS (GPS_PROVIDER) – Cell tower + wifi (NETWORK_PROVIDER) • You cannot request only wifi, just wifi and tower. • You cannot tell the difference between wifi and tower – Except that the accuracy of the tower is 100 s of meters, and accuracy of wifi is 10 s of meters • You can get tower only by turning off wifi
Make new app • New app called android. Localization • Add permissions – Internet – Fine location – Course location • Add Text. View to UI. Set ID to android. Localization. Text. View • In Android. Localization. Activity, add member variable – Text. View android. Localization. Text. View = null; • In on. Create – android. Localization. Text. View = (Text. View)find. View. By. Id(R. id. android. Localization. Text. View);
Getting periodic location updates • Add top of class, add member variable – Location. Manager location. Manager = null; • In on. Create, add – location. Manager = (Location. Manager) get. System. Service(Context. LOCATION_SERVICE); • To start wifi+cell tower locallocation. Manager. request. Location. Updates(Location. Manager. NETWORK_PROVIDER, 0, 0, location. Listener); • ization, add – The 3 rd argument is the minimum time between updates (so, updates should not arrive any faster than this minimum) – The 4 th argument is the minimum distance traveled between updates (so updates should not occur unless the phones has moved this distance) – These arguments are only suggestions. The system might respond faster or slower • If GPS and wifi+cell tower is needed, then two function calls are used – location. Manager. request. Location. Updates(Location. Manager. NETWORK_PROVIDER, 0, 0, location. Listener); – location. Manager. request. Location. Updates(Location. Manager. GPS_PROVIDER, 0, 0, location. Listener); • Note: passive localization is also possible. In this case, the app does not start wifi or gps. But if some other app does, and gets location info, then this app will get the location info too – location. Manager. request. Location. Updates(Location. Manager. PASSIVE_PROVIDER, 0, 0, location. Listener); • When done getting location information, you must unregister with – location. Manager. remove. Updates(location. Listener); – Note, this unregister will unregister everything
location. Listener • • • • • • Location. Listener location. Listener = new Location. Listener() { @Override public void on. Location. Changed(Location location) { String str = new String(); str += "Longitude: "+location. get. Longitude()+" latitude: "+location. get. Latitude(); str += " altitude: " +location. get. Altitude(); if (location. has. Accuracy()) str += " accuracy: "+location. get. Accuracy(); else str += " accuracy is unknown "; if (location. has. Speed()) str += " speed: "+location. get. Speed(); else str += "speed is unknown"; if (location. has. Bearing()) str += "bearing: "+location. get. Bearing(); else str += "bearing is unknown"; str += "provider: "+location. get. Provider(); Log. e("location. Info", str); android. Localization. Text. View. set. Text(str); // this works. It seems to come on the UI thread. But maybe it would be safer to make a run. On. Ui. Thread function } };
• Walk around and try android • Compare android to skyhook and to gps • Other things related to localization that are covered in other lectures – Roll-your-own wifi-based localization – Smoothing localization information (Kalman filter)
- Slides: 6