PageRenderTime 39ms CodeModel.GetById 15ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/documentation/wifilocalizationservice/howto.html

http://eyes-free.googlecode.com/
HTML | 1 lines | 1 code | 0 blank | 0 comment | 0 complexity | d10e4fb957eed1b9df716e2d7f1104ba MD5 | raw file
1<html><head><title></title><style type="text/css">ol{margin:0;padding:0}p{margin:0}.c30{color:#000000;font-size:10pt;font-family:Courier New}.l6_sgmapky48low{list-style-type:disc}.l7_sgmapky48low{list-style-type:circle}.l2_sgmapky48low{list-style-type:square}.l4_sgmapky48low{list-style-type:circle}.c100{margin-left:72.0pt}.c108{margin-left:108.0pt}.l3_sgmapky48low{list-style-type:disc}.c167{padding-left:0pt;line-height:1.15;direction:ltr;margin-left:36.0pt}.l8_sgmapky48low{list-style-type:square}.c22{color:#000000;font-size:14pt;font-family:Arial;font-weight:bold}.c23{padding-top:14.0pt;padding-bottom:4.0pt}.c41{line-height:1.15;text-indent:36.0pt;direction:ltr;margin-left:36.0pt}.l5_sgmapky48low{list-style-type:square}.l1_sgmapky48low{list-style-type:circle}.c3{line-height:1.15;text-indent:0pt;direction:ltr}.c135{margin-left:252.0pt}.c241{background-color:#ffffff}.c1{padding-top:18.0pt;line-height:1.15;text-indent:0pt;direction:ltr;padding-bottom:4.0pt}.c2{color:#000000;font-size:11pt;font-family:Arial}.c94{margin-left:144.0pt}.c0{color:#000000;font-size:18pt;font-family:Arial;font-weight:bold}.l0_sgmapky48low{list-style-type:disc}.c72{font-weight:bold}.c13{color:#000099;font-size:11pt;text-decoration:underline;font-family:Arial}.c51{line-height:1.15;text-indent:36.0pt;direction:ltr}</style></head><body class="c241"><p class="c1"><a name="h.req6jg6c6ror"></a><span class="c0">WiFi Localization Service</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2">WiFi localization service allows collection and tagging WiFi signatures, and localizing using the pre-collected data set. The source code also contains some demo applications showing the different kinds of things that can be done with the service.</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2">The demo applications are located in src/com/whereabout/whereami.</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2">The com.google.whereabout.location.LocationManager provides an easy-to-use wrapper for the WiFi location provider and has a very similar interface to the default </span><span class="c13"><a href="http://developer.android.com/reference/android/location/LocationManager.html">android.location.LocationManager</a></span><span class="c2">. It will handle the WiFi location provider and delegate all other location provider requests to the default android.location.LocationManager. Please note that unlike the default android.location.LocationManager, you will need to remember to explicitly shutdown the WhereAbout LocationManager when your application is quitting.</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2">WiFi localization service currently allows saving WiFi signatures locally on the SD card. App Engine support and sharing of location tagged WiFi signatures will be coming soon. This document is divided into two parts. The first part explains how to use the WiFi localization service API to tag WiFi locations and localize. The second part explains how to use the demo apps.</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3 c23"><a name="h.vq0resby8y4m"></a><span class="c22">WiFi location tagging</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2">First, create the LocationManager object with the default directory path.</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c30">LocationManager locationManager = new LocationManager(context);</span></p><p class="c3"><span class="c30">&nbsp;</span></p><p class="c3"><span class="c2">Alternatively, create the LocationManager object by explicitly specifying the directory to which to save the scans.</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c30">LocationManager locationManager = new LocationManager(context, null,</span></p><p class="c41"><span class="c30">&ldquo;/sdcard/mywifiscans&rdquo;);</span></p><p class="c3"><span class="c30">&nbsp;</span></p><p class="c3"><span class="c2">Synchronously scan and save the WiFi signature.</span></p><p class="c3"><span class="c30">&nbsp;</span></p><p class="c3"><span class="c30">locationManager.saveScan(&ldquo;/sdcard/mywifiscans&rdquo;, &ldquo;SFO&rdquo;, &ldquo;MyOffice&rdquo;, &ldquo;2&rdquo;, &nbsp;</span></p><p class="c51"><span class="c30">&ldquo;MyDesk&rdquo;, 0, 0, latitude, longitude, 4, 20000,</span></p><p class="c51"><span class="c30">new LocationManager.WifiLocationTaggingListener() {</span></p><p class="c51"><span class="c30"> public void onDoneSave(boolean success, String locationName) {</span></p><p class="c51"><span class="c30"> &nbsp;Log.d(&ldquo;Debug&rdquo;, &ldquo;Location tagged.&rdquo;);</span></p><p class="c51"><span class="c30"> }</span></p><p class="c51"><span class="c30">});</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3 c23"><a name="h.j5wacodqc6ya"></a><span class="c22">WiFi localization</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2">The service supports localization in two modes: continuous and on-demand.</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2 c72">Continuous Localization:</span><span class="c2"> In this mode, location is computed every 1 second. Due to WiFi signal fluctuations, this mode tends to produce outliers, as a result of which the estimated location can be relatively unstable. The last two parameters to </span><span class="c30">requestLocationUpdates</span><span class="c2"> are ignored.</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c30">LocationManager locationManager = new LocationManager(context);</span></p><p class="c3"><span class="c30">locationManager.startWifiService();</span></p><p class="c3"><span class="c30">locationManager.requestLocationUpdates(</span></p><p class="c41"><span class="c30">LocationManager.INDOOR_WIFI_LOCATION_PROVIDER, 1000,</span></p><p class="c41"><span class="c30">0, new LocationListener() {</span></p><p class="c41"><span class="c30"> public void onLocationChanged(final Location location) {</span></p><p class="c41"><span class="c30"> &nbsp;Log.d(&ldquo;Debug&rdquo;, location.getLatitude() + &ldquo;, &ldquo; +</span></p><p class="c51 c94"><span class="c30">location.getLongitude());</span></p><p class="c3"><span class="c30"> &nbsp; &nbsp;// Additional information can be obtained via extras</span></p><p class="c3"><span class="c30"> &nbsp; &nbsp;Bundle extrasBundle = location.getExtras();</span></p><p class="c51 c100"><span class="c30">}</span></p><p class="c100 c51"><span class="c30">public void onProviderDisabled(String provider) {}</span></p><p class="c100 c51"><span class="c30">public void onProviderEnabled(String provider) {}</span></p><p class="c100 c51"><span class="c30">public void onStatusChanged(String provider, int status,</span></p><p class="c51 c108"><span class="c30">Bundle extras) {}</span></p><p class="c41"><span class="c30">);</span></p><p class="c3"><span class="c30">&nbsp;</span></p><p class="c3"><span class="c2 c72">On-Demand Localization:</span><span class="c2"> In this mode, the service performs multiple location computations for the specified duration, and picks the location that got the best overall matching score. The estimated location tends to be more stable in this mode. </span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2">Note: A current limitation of the WiFi localization service causes continuous localization to pause when an on-demand location is requested.</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c30">LocationManager locationManager = new LocationManager(context);</span></p><p class="c3"><span class="c30">locationManager.startWifiService();</span></p><p class="c3"><span class="c30">// Scan for 4 seconds and pick the winning location</span></p><p class="c3"><span class="c30">locationManager.localizeWithWifi(4000,</span></p><p class="c51"><span class="c30">new WifiLocalizationListener() {</span></p><p class="c41"><span class="c30">public void onWifiLocalizationResult(int status,</span></p><p class="c51 c135"><span class="c30"> Location result) {</span></p><p class="c41"><span class="c30"> Log.d(&ldquo;Debug&rdquo;, location.getLatitude() + &ldquo;, &ldquo; +</span></p><p class="c108 c51"><span class="c30">location.getLongitude());</span></p><p class="c3"><span class="c30"> &nbsp; // Additional information can be obtained via extras</span></p><p class="c3"><span class="c30"> &nbsp; Bundle extrasBundle = location.getExtras();</span></p><p class="c41"><span class="c30">}</span></p><p class="c51"><span class="c30">});</span></p><p class="c3"><span class="c30">&nbsp;</span></p><p class="c3"><span class="c2 c72">Location extras:</span><span class="c2"> The Location object obtained in both the continuous and on-demand modes, contains additional data in the extras field. The contents of the extras and its description is given below:</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2">Here&rsquo;s how you can obtain the extras from the location:</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c30">Bundle extrasBundle = location.getExtras();</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2">The meta data contains following additional information about the top estimated locations.</span></p><ol class="l0_sgmapky48low"><li class="c167 l0_sgmapky48low" value="1"><span class="c2">Names of top matching locations</span></li></ol><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2"> </span><span class="c30">String[] names = extrasBundle.getStringArray(MATCH_LOCATIONS);</span></p><p class="c3"><span class="c2">&nbsp;</span></p><ol class="l0_sgmapky48low"><li class="c167 l0_sgmapky48low" value="2"><span class="c2">Match scores (lower is better)</span></li></ol><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2"> </span><span class="c30">double[] scores = extrasBundle.getDoubleArray(MATCH_SCORES);</span></p><p class="c3"><span class="c2">&nbsp;</span></p><ol class="l0_sgmapky48low"><li class="c167 l0_sgmapky48low" value="3"><span class="c2">X-coordinates</span></li></ol><p class="c3"><span class="c2">&nbsp;</span></p><p class="c51"><span class="c30">int[] x = extrasBundle.getIntArray(MATCH_XCOORDS);</span></p><p class="c3"><span class="c2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></p><ol class="l0_sgmapky48low"><li class="c167 l0_sgmapky48low" value="4"><span class="c2">Y-coordinates</span></li></ol><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2"> </span><span class="c30">int[] y = extrasBundle.getIntArray(MATCH_YCOORDS);</span></p><p class="c3"><span class="c2">&nbsp;</span></p><ol class="l0_sgmapky48low"><li class="c167 l0_sgmapky48low" value="5"><span class="c2">Latitudes</span></li></ol><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2"> </span><span class="c30">double[] lat = extrasBundle.getDoubleArray(MATCH_LATITUDES);</span></p><p class="c3"><span class="c2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></p><ol class="l0_sgmapky48low"><li class="c167 l0_sgmapky48low" value="6"><span class="c2">Longitudes</span></li></ol><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2"> </span><span class="c30">double[] lon = extrasBundle.getDoubleArray(MATCH_LONGITUDES);</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2">In addition, an interpolated value of final X-Y coordinates and lat-lng are also provided.</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c30">int finalX = extrasBundle.getInt(FINAL_X);</span></p><p class="c3"><span class="c30">int finalY = extrasBundle.getInt(FINAL_Y);</span></p><p class="c3"><span class="c30">double finalLat = extrasBundle.getDouble(FINAL_LAT);</span></p><p class="c3"><span class="c30">double finalLon = extrasBundle.getDouble(FINAL_LON);</span></p><p class="c3"><span class="c2">&nbsp;</span></p><p class="c3"><span class="c2">&nbsp;</span></p></body></html>