Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android wifi-based localization. Localization types Android allows (location providers) – GPS (GPS_PROVIDER) – Cell tower + wifi (NETWORK_PROVIDER) You.

Similar presentations


Presentation on theme: "Android wifi-based localization. Localization types Android allows (location providers) – GPS (GPS_PROVIDER) – Cell tower + wifi (NETWORK_PROVIDER) You."— Presentation transcript:

1 Android wifi-based localization

2 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 100s of meters, and accuracy of wifi is 10s of meters You can get tower only by turning off wifi

3 Make new app New app called androidLocalization Add permissions – Internet – Fine location – Course location Add TextView to UI. Set ID to androidLocalizationTextView In AndroidLocalizationActivity, add member variable – TextView androidLocalizationTextView = null; In onCreate – androidLocalizationTextView = (TextView)findViewById(R.id. androidLocalizationTextView);

4 Getting periodic location updates Add top of class, add member variable – LocationManager locationManager = null; In onCreate, add – locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); To start wifi+cell tower local locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 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 – locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); – locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); 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 – locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, locationListener); When done getting location information, you must unregister with – locationManager.removeUpdates(locationListener); – Note, this unregister will unregister everything

5 locationListener LocationListener locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { String str = new String(); str += "Longitude: "+location.getLongitude()+" latitude: "+location.getLatitude(); str += " altitude: " +location.getAltitude(); if (location.hasAccuracy()) str += " accuracy: "+location.getAccuracy(); else str += " accuracy is unknown "; if (location.hasSpeed()) str += " speed: "+location.getSpeed(); else str += "speed is unknown"; if (location.hasBearing()) str += "bearing: "+location.getBearing(); else str += "bearing is unknown"; str += "provider: "+location.getProvider(); Log.e("locationInfo",str); androidLocalizationTextView.setText(str); // this works. It seems to come on the UI thread. But maybe it would be safer to make a runOnUiThread function } };

6 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)


Download ppt "Android wifi-based localization. Localization types Android allows (location providers) – GPS (GPS_PROVIDER) – Cell tower + wifi (NETWORK_PROVIDER) You."

Similar presentations


Ads by Google