6
Android wifi-based localization

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

Embed Size (px)

Citation preview

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

Android wifi-based localization

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

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

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

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

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

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 locallocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,

0, locationListener);• ization, add

– The 3rd argument is the minimum time between updates (so, updates should not arrive any faster than this minimum)

– The 4th 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

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

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• }• };

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

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