Matchinguu droidcon presentation

  • View
    414

  • Download
    0

Embed Size (px)

Transcript

  • 1.LOCATION BASED SOLUTIONS IN THE ANDROID REALMThere are many ways to Rome, some may look quite surprising Jrgen Fey . CTO matchinguu

2. AGENDA Matchinguubackgrounder Loca2onProviderTechnologiesforAndroiddevices Usecases 3. SOME INFO ABOUT US WE ARE THE EXPERT FOR LOCATION BASED SOLUTIONS WITH THE CLEAR FOCUS ON MOBILE. matchinguuisastartupbasedinMunich, Germany(headcount:9+).Westartedin2013 withacleartarget: matchinguuisprovidingacomprehensiveAPIfor AndroidandiOSaswellastheneededbackend servicesandhardwareinfrastructuretoallow businessestointegrateevencomplexLBS scenariosfast. Yes,wealsobuiltcomplete,customapps. 4. OUR SERVICES ANDROID API EasytointegrateAPIfor variousloca2on providers.Eventsystem. Powermanagement. iOS API EasytointegrateAPIfor variousloca2on providers.Eventsystem. Powermanagement. BACKEND SaaS Customerdashboardto controlloca2onsand events.Heatmaps,Process automa2on,repor2ngand more HARDWARE Localhotspot,business intelligence,Beacons, Backendadaptersand more. 5. LOCATION PROVIDERS ON MOBILE PLATFORMS CELL-ID WLAN GPS FUSED LOCATION PROVIDER GEOHASH SENSORS GEOFENCES BEACONS IOT NFC Manyop(ons ThemobileplaSorm(Android) providesawiderangeofLBS op2ons. Combineand/orusewisely Whileonemightbetemptedto usethebestprovidersatanygiven 2mejusttobesavetheuserwill nottoleratetheresul2ngpower drain. 6. CELL-ID Ifthemobiledeviceisconnectedtoanetworkcell(throughthemodempart) theCell-IDprovidesaclearloca2onngerprint Thenetworkbasesta2ons(BaseTransceiverSta2on,Cell)aresta2c loca2onreferencepoints Theloca2onsareknowntotheproviders,Googleandotherservice providers Triangula2onallowsonetoguessaloca2onwithsmallererrorburden Accuracy:From20km PublicCell-IDdatabases OpenCellID(h_p://wiki.opencellid.org/wiki/API) unwiredlabsLoca2onAPI(h_p://unwiredlabs.com/) 7. CELL-ID UseTelephonyManagertoretrievecurrent CellID MNC(MobileNetworkCode) MCC(MobileCountryCode) LAC(Loca2onAreaCode) UsePhoneStateListenerandonCellInfoChangedcallbacktoretrievenewCell-ID info(devicemustbeawake!wakelock) PowerFactor:verylow,forconstantbackgroundupdateshigher AndroidReference: h_p://developer.android.com/reference/android/telephony/CellLoca2on.html 8. CELL-ID Example TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); GsmCellLocation cellLocation = (GsmCellLocation)tManager.getCellLocation(); String networkOperator = tManager.getNetworkOperator(); String mcc = networkOperator.substring(0, 3); String mnc = networkOperator.substring(3); int cid = cellLocation.getCid(); int lac = cellLocation.getLac(); 9. CELL-ID NiceAndroidappS: OpenSignal CellWIDGET 10. CELL-ID Sidenote: ByusinganIMSIcatcher(youmightGoogleforthatone...)anen2tyother thantheocialprovidermayprovideyouwithanalterna2veCell,which takesoverthetaskofnetworkconnec2vity. IMSIcatcherdetec2on: h_p://forum.xda-developers.com/showthread.php?t=1422969 11. WLAN TheWLANsignalisaperfectreferenceforquiteaccurateloca2oninfo. HowdoesGooglegetthisvaluableinfo? ItsYOU! Addthefollowingingredientstothesweetcake: AndroidDevice GPSandotherLoca2onProviders Networkconnec2on NoneedtouseMapsetctheydoitanyways(occasionally,anonymously) BTW:Apple,Microsoketalareworkingthesameway PublicDatabase:h_p://www.openwlanmap.org/ 12. WLAN EachWLANAccessPointcanbedenedby SSID(ServiceSetIden2er) MACAddress(uniquenetworkhardwareaddress) BymergingtheinfoaboutanSSIDandallotherLoca2onProviders(whenavailable)itis possibletobuildupaLoca2onDatabaseusingjustSSIDs. ThisiswhatishappeningeachSSIDcan/maybeusedforLoca2oninfo KnownSSIDscanbeusedforinhouseapps(CustomWLANProximity) PowerFactor:highwhenalwayson,manageableforproximityusecase AndroidTutorial:h_p://www.tutorialspoint.com/android/android_wi_.htm 13. GEOHASH GeoHashingisusingaspeciallypreparedtextinfoforhighaccuraryloca2on. AsingleGeoHashstringprovidesinfoforatwocoordinateloca2on Dependingonthestringlengththeaccuracyincreases 8characters:38/19m 12characters:4/2cm h_p://unterbahn.com/2009/11/metric-dimensions-of-geohash-par22ons-at-the-equator/ 14. GEOHASH 15. GEOHASH 16. GEOHASH Example:h_p://geohash.org/u33d8m58g(GleisdreieckBerlin) SomedatabasessupportGeoHashing(MongoDB,SOLRetc.) MatchinguuusestheGeoHashinfoaspartoftheSSIDforcustomerAPs SSID:magic_u33d8m58g_zH232J_poweredbymatchinguu AnyoneinterestedtoprovideanopensourcerepoforsuchkindoflocSSID?(lets talk) Nicedemo:h_p://geohash.gofreerange.com/ 17. GPS Thebread-and-bu_erLoca2onprovider. DedicatedGPShardware Accuracyforpublicusescases:downto3m Updaterate:downto1s TTFF(TimeToFirstFix):maytakeloooong needstoseeatleast3satellitesthemorethebe_er usuallyinlessthanaminute,buts2ll... PowerFactor:veryhigh(80..150mA) AndroidExample: h_p://www.codeproject.com/Ar2cles/665527/A-GPS-Loca2on-Ploqng-Android- Applica2on 18. GPS ForGPSandanyotherloca2onproviders: UseBroadcastReceiverorServicewithLocaEonListenertosetuptrue backgroundprocessing. BroadcastReceiver:Androidaddsyourreceiverduringboot2me(iflistedin Manifest).Quiteniceforappsworkinginbackground. Alterna2ve:Registerduringrun2meandsendanPendingIndent.Thisis be_erwhenyouneedtocopewithstates. Service:Generallyabitheavierbuts2llalsook. 19. GPS Unocialfeatures: http://androidxref.com/ 20. GPS Whenusedwisely,GPSisatopnotchproviderforaccurateloca2on informa2onuseitwiselyandonlywhenneededandyouaresave. Donotuseitasthesolesource,ifpossible. Alwayskeepthepowerconsump2oninmind. GPSmustbeturnedonincaseyouneedtoasktheusertoac2vate. 21. SENSORS Sensorsareplayinganincreasinglyimportantrolewhendealingwithloca2on-awaresolu2ons. Theymaybeusedtohelpguessingmovements,henceanewloca2onorjusttoreducepower consump2on. TherearethreegeneralsensorgroupssupportedbyAndroid: Mo2onsensors Accelerometer Gravity Gyroscope/Rota2onalVector Environmentalsensors Temperatur Light/Sound AirPressure/Humidity Posi2onsensors Orienta2on Magnetometer 22. SENSORS Thenumberofavailablesensors,theircapabili2esandaccuracydoesvary! Thereisnothingasagenericsensorineachcategory. Theremightbemul2plesensorspercategorywithdierentbehavior. Lotsofsupliersforthesamesensorcategory. Somesensorsaresokwareonlytheyaremodellingtherealitybyusing othersensors(accelera2onetc.). Source:EETimes 23. SENSORS AccesstothesetofavailablesensorsisprovidedbytheSensorFramework. ThesensorsupportstartedtobequitecompletefromAPI9(Android2.3). SensorEventListener: onAccurayChanged onSensorChanged SensorEventprovidesthenewsetofdata(sensorspecic) 24. SENSORS Sensorsarealsousedtodetect/inferuserbehavior: SignicantMo2onSensor(SensorManager):Asignicantmo1onisamo1on thatmightleadtoachangeintheuser'sloca1on;forexamplewalking,biking, orsi@nginamovingcar. mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION); mTriggerEventListener = new TriggerEventListener() { @Override public void onTrigger(TriggerEvent event) { // Do work } }; mSensorManager.requestTriggerSensor(mTriggerEventListener, mSensor); 25. SENSORS GooglePlay2013:newAcEvityRecogniEonfeaturetoprovideabestguess ofthecurrentuserac2vity.Basedonsensorinput. ON_FOOT IN_VEHICLE ON_BYCICLE STILL TILTING New:Running,Walking Generatesresultswithaprobability. Lowpowerimplementa2onmaybeusedinsteadofhomegrownsolu2ons basedonrawsensordata. 26. ANDROID LOCATION MANAGER Loca2onManagerusedtobethecentralinstancetoreceiveLoca2oninfo GPS Cell-ID WLAN SupportfromAPI1 NoPlayStorelibneeded Appneedstoaskexplicitly Somecalcvoodooneeded 27. ADDING SOME SENSOR INFO Byaddingaddi2onalhelpfromthesensorsonemightbeabletobe_erguess oractuallyknowthecurrentloca2on 28. HOMEBREW LOCATION SOLUTION Byusingalloftheshownloca2onprovidersourcesitispossibletogetaquite op2mizedloca2oninforma2on. Lotsofneededsupportcode Op2mizingthebetsprac2ceparametersdonebyappdeveloper Parametersmightbedierentonotherhardware Itisimportanttocheckforavailabilityofeachproviderrst Essen2altocopewithongoingstatuschanges(oine/online,on/o) Formostdevicesthereisanalterna2ve:FusedLoca2onProvider 29. FUSED LOCATION PROVIDER TheFusedLocaEonProvidermergestheavailablesourcesintoonesingle source: GPS Cell-ID WLAN Sensors PartoftheGooglePlaypackage Notavailableonalldevices! IfthereisaPlayStoreapp,thereisthePlaypackage Cumbersomeprocesstoaddintoarooteddevice..... 30. FUSED LOCATION PROVIDER 31. FUSED LOCATION PROVIDER locRequest=Loca2onRequest.create() .setPriority(Loca2onRequest.BALANCED_POWER_ACCURACY) .setInterval(10000)//10s .setExpira2onDura2on(120000)//stopaker2minfromNOW .setSmallestDisplacement(25) //25mmin.movementforupdate .setNumUpdates(5) //stopaker3updates mLoca2onClient.requestLoca2onUpdates(locRequest,this) 32. FUSED LOCATION PROVIDER Loca2onClientneedstoimplement GooglePlayServicesClient.ConnecEonCallbacks GooglePlayServices.onConnecEonFailedListener LocaEonListner Callbacks: onConnected onDisconnected onConnecEonFailed onLocaEonChanged 33. FUSED LOCATION PROVIDER Priorityop2onsandpowerdrainimpact(Source:Google,GalaxyNexus): Priority Interval Drain(%perh) Accuracy HIGH_ACCURACY 5s 7.25% ~10m BALANCED_POWER 20s 0.6% ~40m NO_POWER N/A small ~Cellrelated 34. FUSED LOCATION PROVIDER Iamhere!No,imovedabit.Nowiamhere.Wait,iamthere. 35. FUSED LOCATION PROVIDER AlwayschecktheaccuracyvalueofANYresultbeforeanyfurtherac2on.Even ifyougeta7digitvalueyoumays2llbeoquiteabit. 36. GEOFENCES AGeoFenceisjustaradialarea,denedbytheloca2oncenterandthe radius.Asaresultwegetavirtualradialfence. 37. GEOFENCES OLD STYLE Homebrewversion-Howonehadtodoitbefore(basedon Loca2onManager): Intent intent = new Intent(PROX_ALERT_INTENT); PendingIntent proximityIntent = PendingIntent.getBroadcast(this, intentnum, intent, 0); locationManager.addProximityAlert( latitude, longitude, POINT_RADIUS, PROX_ALERT_EXPIRATION, proximityIntent) .... 38. GEOFENCES OLD STYLE Whiletheoldstylemightlookgoodithadonemajordrawback: Itisusingwaytomuchba_erypower. Reason:Nocontroloverloca2onrequestupdateparameterslikeupd