context-aware computing - unibo.itdifelice/sm/slides/sm15.pdf · context-aware computing apis for...

70
Context-aware Computing APIs for Location-based Services Prof. Marco Di Felice Department of Computer Science and Engineering University of Bologna Mobile Systems h"p://www.cs.unibo.it./difelice/sm/

Upload: ngocong

Post on 08-Jun-2018

218 views

Category:

Documents


1 download

TRANSCRIPT

Context-aware Computing APIs for Location-based Services

Prof. Marco Di Felice Department of Computer Science and Engineering

University of Bologna

Mobile Systems

h"p://www.cs.unibo.it./difelice/sm/

APIs for Loca,on-based services

2APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICES

MARCODIFELICE

COMPONENTSofLOCATION-BASEDSERVICESARCHITECTURE

Source:h"p://geoawesomeness.com/

Ø  WewillnowfocusontheServiceandContentProviderLayer…

APIs for Loca,on-based services

3

q  SeveralgeoservicesandgeolocaEonAPIsareavailable(atleastforoutdoorscenarios).

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

APIs for Loca,on-based services

4

q  GeolocaEonAPIsforlocaRon-basedservices

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

h"p://www.programmableweb.com/news/61-geolocaRon-apis-panoramio-google-gears-and-yahoo/2012/03/14

APIs for Loca,on-based services

5

q  SeveralgeoservicesandgeolocaEonAPIsareavailable(atleastforoutdoorscenarios).

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

APIs for Loca,on-based services

6

q  W3CGeolocaEonAPIisaneffortbytheWorldWideWebConsorRum(W3C)tostandardizeaninterfaceforretrievingthegeographicallocaRoninformaRonforaclient-side(Web)device.²  HTML5GeolocaRonAPIissupportedbymostofthebrowser²  GeolocaRondata:laRtude,longitude,accuracy,alRtude,

alRtude,alRtudeAccuracy,speed,heading,Rmestamp²  Mainmethods:getCurrentPosiRon()andwatchPosiRon()

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

APIs for Loca,on-based services

7

q  HTML5GeolocaEonAPIcodeexample

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

<script>varx=document.getElementById("demo");functiongetLocation(){if(navigator.geolocation){navigator.geolocation.getCurrentPosition(showPosition);}else{x.innerHTML="Geolocationisnotsupportedbythisbrowser.";}}functionshowPosition(position){x.innerHTML="Latitude:"+position.coords.latitude+"<br>Longitude:"+position.coords.longitude;}</script>

DocumentaRonandsourcecodeavailableat:hKp://www.w3schools.com/html/html5_geolocaEon.asp

APIs for Loca,on-based services

8

q  HTML5GeolocaEonAPIcodeexample–errorhandling

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

functionshowError(error){switch(error.code){caseerror.PERMISSION_DENIED:x.innerHTML="UserdeniedtherequestforGeolocation."break;caseerror.POSITION_UNAVAILABLE:x.innerHTML="Locationinformationisunavailable."break;caseerror.TIMEOUT:x.innerHTML="Therequesttogetuserlocationtimedout."break;caseerror.UNKNOWN_ERROR:x.innerHTML="Anunknownerroroccurred."break;}

DocumentaRonandsourcecodeavailableat:hKp://www.w3schools.com/html/html5_geolocaEon.asp

APIs for Loca,on-based services

9

q  HTML5GeolocaEonAPIcodeexample–mapdisplay

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

functionshowPosition(position){varlatlon=position.coords.latitude+","+position.coords.longitude;varimg_url="http://maps.googleapis.com/maps/api/staticmap?center="+latlon+"&zoom=14&size=400x300&sensor=false";document.getElementById("mapholder").innerHTML="<imgsrc='"+img_url+"'>";}

DocumentaRonandsourcecodeavailableat:hKp://www.w3schools.com/html/html5_geolocaEon.asp

APIs for Loca,on-based services

10

q  SeveralgeoservicesandgeolocaEonAPIsareavailable(atleastforoutdoorscenarios).

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

APIs for Loca,on-based services

11

q  GoogleMapsAPI

²  HTTP-basedWebserviceAPI

² WebclientAPI(Javascript)

²  ProgramminglanguageAPI(Java,Python)

² MobileOSAPI(Android,iOS)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

12

q  GoogleMapswebservicesareacollecRonofHTTPinterfacestoGoogleservicesprovidinggeographicdataformap-relatedapplicaRons.²  RESTfulservices;resourcesareidenRfiedbyaidenRfier,and

manipulatedbyusingacommonsetofHTTPmethods.²  OutputsarereturnedinJSON/XMLformats.²  AregistraEonkeyisneededtoaccesstheservices.

h"ps://console.developers.google.com

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

13

q MainGoogleMapswebservices²  GoogleMapsGeolocaEonAPI²  GoogleMapsElevaRonAPI²  GoogleMapsGeocodingAPI²  GoogleMapsDirecRonsAPI²  GoogleMapsRoadsAPI²  GoogleMapsTimeZoneAPI²  GooglePlacesAPI

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

14

q  TheGoogleMapsGeolocaEonAPIallowsdeterminingthecurrentlocaEon(plustheaccuracyradius)

²  GeolocaRonisperformedbyconsideringfingerprinRng/triangulaRontechniques,basedoncellulartowersandWiFinetworkstheuserscandetectattheirlocaRons(providedasinputs).

²  Requests/responsesareforma"edinJSON,andtransmi"edusingPOSTmethodsoverHTTPS.

²  TheAPIkeyisneededtoidenRfytheapplicaRon(andthequota)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

https://www.googleapis.com/geolocation/v1/geolocate?key=YOUR_API_KEY

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

15

q  Therequestbodymustbeforma"edinJSON.

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

{"homeMobileCountryCode":310,"homeMobileNetworkCode":410,"radioType":"gsm","carrier":"Vodafone","considerIp":"true","cellTowers":[//CellTowerObjects.],"wifiAccessPoints":[//WiFiAccessPointObjects.]}

HOMENETWORKCOUNTRYCODE

HOMENETWORKNETWORKCODE

MOBILERADIOTYPE:gsm,lte,cdma,wcdma

UseIPaddresswhenwirelessnetworkinfoarenotavailable

Networkprovidername

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

16

q  Therequestbodymustbeforma"edinJSON.

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

{"cellTowers":[{"cellId":42,"locationAreaCode":415,"mobileCountryCode":310,"mobileNetworkCode":410,"age":0,"signalStrength":-60,"timingAdvance":15}]}

CELLTOWERSOBJECTEXAMPLE

TIMEOFARRIVALfrommobilenodetothebasestaRon

RECEIVEDSIGNALSTRENGTH(indbm)

UniqueCELLIDENTIFIER(mandatory)

AreaandNetworkIdenEfiers(mandatory)

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

17

q  Therequestbodymustbeforma"edinJSON.

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

"wifiAccessPoints":[{"macAddress":"01:23:45:67:89:AB","signalStrength":-65,"age":0,"channel":11,"signalToNoiseRaRo":40}]

WIFIOBJECTEXAMPLE

NOISEoverRECEIVEDSIGNAL(indb)

WIFIchannelusedbytheAP

MACADDRESSoftheAP(mandatory)

ReceivedSignalStrength(RSS)indbm

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

18

q  Theresponsebodymustbeforma"edinJSON.

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

{"locaEon":{"lat":51.0,"lng":-0.1},"accuracy":1200.4}

EsRmatedlaEtudeandlongitudeoftheuser(indegrees)

LocalizaEonerror,definedasaradius(inmeters)ofacirclecenteredattheesRmatedlocaRonreturnedabove.

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

19

q MainGoogleMapswebservices²  GoogleMapsGeolocaRonAPI²  GoogleMapsElevaEonAPI²  GoogleMapsGeocodingAPI²  GoogleMapsDirecRonsAPI²  GoogleMapsRoadsAPI²  GoogleMapsTimeZoneAPI²  GooglePlacesAPI

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

20

q  TheGoogleMapsElevaEonAPIallowsdeterminingelevaRondataforalllocaRonsonthesurfaceoftheearth,includingdepthlocaRonsontheoceanfloor.²  ElevaRondataareavailablethroughmeasurementsorinterpolaRon.

²  Requests/responsesareforma"edinJSONorXML,andtransmi"edusingPOSTmethodsoverHTTPS.

²  RequestscanbeissuedforfordiscretelocaRonsorforanorderedpath

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

https://maps.googleapis.com/maps/api/elevation/outputFormat?parameters

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

21

q  PosiEonalrequestsareindicatedthroughuseofthelocaRonsparameter,indicaRngelevaRonrequestsforthespecificlocaRons(laRtude/longitudevalues).

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

https://maps.googleapis.com/maps/api/elevation/json?locations=39.7391536,-104.9847034&key=YOUR_API_KEY

{"results":[{"elevation":1608.637939453125,"location":{"lat":39.73915360,"lng":-104.98470340},"resolution":4.771975994110107}],"status":"OK”} MinimumdistanceofinterpolaEon(inmeters)

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

22

q  PosiEonalrequestscanrefertotheelevaRondataalongapathatspecifiedintervals.

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

https://maps.googleapis.com/maps/api/elevation/json?path=36.578581,-118.291994|36.23998,-116.83171&samples=3&key=YOUR_API_KEY

² PathisacoupleoflaRtude/longitudeofthestartandendpoint² SampleisthenumberofsamplepointsalongapathforwhichtoreturnelevaRondata

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

23

q  PosiEonalrequestscanrefertotheelevaRondataalongapathatspecifiedintervals.

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

{"results":[{"elevaRon":4411.941894531250,"locaRon":{"lat":36.5785810,"lng":-118.2919940},"resoluRon":19.08790397644043},

{"elevaRon":1381.861694335938,"locaRon":{"lat":36.41150289067028,"lng":-117.5602607523847},"resoluRon":19.08790397644043},{"elevaRon":-84.61699676513672,"locaRon":{

"lat":36.239980,"lng":-116.831710},"resoluRon":19.087903}],"status":"OK"}

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

24

q MainGoogleMapswebservices²  GoogleMapsGeolocaRonAPI²  GoogleMapsElevaRonAPI²  GoogleMapsGeocodingAPI²  GoogleMapsDirecRonsAPI²  GoogleMapsRoadsAPI²  GoogleMapsTimeZoneAPI²  GooglePlacesAPI

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

25

q  GeocodingistheprocessofconverRngaddressesintogeographiccoordinates(laRtude/longitude).

²  ReversegeocodingistheprocessofconverRnggeocoordinates(laRtude/longitude)intosymbolicaddresses(e.g.naRon,city,address).

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

https://maps.googleapis.com/maps/api/geocode/output?parameters

² OutputcanbeJSONorXML² Parametersaredifferentforgeocodingandreversegeocoding

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

26

q  GeocodingistheprocessofconverRngaddressesintogeographiccoordinates(laRtude/longitude)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

PARAMETERSOFTHEGEOCODINGSERVICE

² AddressàThestreetaddressintheformatusedbythenaRonalpostalservice² ComponentsàAcomponentfilterofthegeocodingrequest

ü  routematcheslongorshortnameofaroute.ü  localitymatchesagainstbothlocalityandsublocalitytypes.ü  administrative_areamatchesalltheadministraRve_arealevels.ü  postal_codematchespostal_codeandpostal_code_prefix.ü  countrymatchesacountrynameoratwole"erISO3166-1countrycode.

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

27APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICES

MARCODIFELICE

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY

{"results":[{…"formaKed_address":"1600AmphitheatreParkway,

MountainView,CA94043,USA","geometry":{"locaRon":{"lat":37.4224764,"lng":-122.0842499},"locaRon_type":"ROOFTOP”,

"viewport":{"northeast":{"lat":37.4238253802915,"lng":-122.0829009197085},"southwest":{"lat":37.4211274197085,"lng":-122.0855988802915}}…

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

28

q MainGoogleMapswebservices²  GoogleMapsGeolocaRonAPI²  GoogleMapsElevaRonAPI²  GoogleMapsGeocodingAPI²  GoogleMapsDirecEonsAPI²  GoogleMapsRoadsAPI²  GoogleMapsTimeZoneAPI²  GooglePlacesAPI

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

29

q  GoogleMapsDirecEonsAPIallowscalculaRngdirecRonsbetweenlocaRons(non-trackingservice).

²  DirecEonsmayspecifyorigins,desRnaRonsandwaypoints²  Result(JSON/XML)containalistofwaypoints²  DirecRonscanbeprovidedforseveralmodesoftransportaRon,

includingtransit,driving,walkingorcycling.²  TimeintrafficcanbeesRmated.²  Preferencesfortransitroutes(less_walkingorfewer_transfers)

canbeprovidedasinput.APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICES

MARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

30

q  GoogleMapsDirecEonsAPIallowscalculaRngdirecRonsbetweenlocaRons(non-trackingservice).

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&avoid=highways&mode=cycling&key=YOUR_API_KEY

origin/destinationàaddressorgeocoordinatesmodeàdriving,walking,cycling,transitwaypointsàarrayofwaypoints,expressedascoordinatesoraddressesavoidàtolls,highways,ferriesorindoorarrival_time/departure_timeàusedfortransitdirecRonstransit_modeàpreferredmodesoftransit(bus,subway,train,tram,rail)unitsàdistanceunittodisplayresults…

SOMEPARAMETERS

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

31

q MainGoogleMapswebservices²  GoogleMapsGeolocaRonAPI²  GoogleMapsElevaRonAPI²  GoogleMapsGeocodingAPI²  GoogleMapsDirecRonsAPI²  GoogleMapsRoadsAPI²  GoogleMapsTimeZoneAPI²  GooglePlacesAPI

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

32

q  GoogleMapsRoadsAPIallowsmappingGPScoordinatestothegeometryoftheroad,andtodeterminethespeedlimitalongtheroadsegments.

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

https://roads.googleapis.com/v1/speedLimits?parameters&key=YOUR_API_KEY

² pathàListofcoordinates(laRtude/longitude),separatedbycommas² placeIdàplaceIDoftheroadsegment,returnedbythesnapToRoadsmethod

² unitsàspeedlimitsinkilometersormilesperhour.

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

33APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICES

MARCODIFELICE

h"ps://roads.googleapis.com/v1/speedLimits?placeId=ChIJ1Wi6I2pNFmsRQL9GbW7qABM&placeId=ChIJ58xCoGlNFmsRUEZUbW7qABM&key=YOUR_API_KEY

"speedLimits":[{"placeId":"ChIJ1Wi6I2pNFmsRQL9GbW7qABM","speedLimit":60,"units":"KPH"},{"placeId":"ChIJ58xCoGlNFmsRUEZUbW7qABM","speedLimit":60,"units":"KPH"},}]

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

34

q MainGoogleMapswebservices²  GoogleMapsGeolocaRonAPI²  GoogleMapsElevaRonAPI²  GoogleMapsGeocodingAPI²  GoogleMapsDirecRonsAPI²  GoogleMapsRoadsAPI²  GoogleMapsTimeZoneAPI²  GooglePlacesAPI

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

35

q  TheGoogleMapsTimeZoneAPIallowsrequesRngtheRmezoneforalocaRonontheearth,aswellasthatlocaRonRmeoffsetfromtheUTC

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

https://maps.googleapis.com/maps/api/timezone/outputFormat?parameters

²  locaEonàcomma-separatedlat,lngtuple(eg.locaRon=-33.86,151.20)² EmestampàdesiredRmeassecondssincemidnight,January1,1970UTC.

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

36

q  TheGoogleMapsTimeZoneAPIallowsrequesRngtheRmezoneforalocaRonontheearth,aswellasthatlocaRonRmeoffsetfromtheUTC

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&key=YOUR_API_KEY

{"dstOffset":0,"rawOffset":-28800,"status":"OK","timeZoneId":"America/Los_Angeles","timeZoneName":"PacificStandardTime"}

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

37

q MainGoogleMapswebservices²  GoogleMapsGeolocaRonAPI²  GoogleMapsElevaRonAPI²  GoogleMapsGeocodingAPI²  GoogleMapsDirecRonsAPI²  GoogleMapsRoadsAPI²  GoogleMapsTimeZoneAPI²  GooglePlacesAPI

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

38

q  TheGooglePlacesAPIreturnsinformaRonaboutplaces,definedasestablishments,geographiclocaRons,orprominentpointsofinterest.

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

² PlaceSearchesreturnalistofplacesbasedonauser'slocaRonorsearchstring.² PlaceDetailsrequestsreturninformaRonaboutaspecificPlace(e.g.reviews)

² PlaceAddallowaddingdatatotheGooglePlacesdatabase² PlacePhotosgivesaccesstothePlacerelatedphotosstoredinGoogle'sPlacedatabase.² PlaceAutocompletecanbeusedtoautomaRcallyfillinthenameand/oraddressofaplace² QueryAutocompletecanbeusedtoprovideaquerypredicRonservicefortext-based

geographicsearches,byreturningsuggestedqueriesasyoutype.

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

39

q  TheGooglePlacesAPIreturnsinformaRonaboutplaces,definedasestablishments,geographiclocaRons,orprominentpointsofinterest.

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

https://maps.googleapis.com/maps/api/place/nearbysearch/jsonlocation=-33.8670522,151.1957362&radius=500&type=restaurant&name=Italia&key=YOUR_API_KEY

https://maps.googleapis.com/maps/api/place/radarsearch/json?location=51.503186,-0.126446&radius=5000&type=museum&key=YOUR_API_KEY

https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants+in+Sydney&key=

DocumentaRonandsourcecodeavailableat:hKps://developers.google.com/maps/web-services/

APIs for Loca,on-based services

40

q  GoogleMapsAPI

²  HTTP-basedWebserviceAPI

² WebclientAPI(Javascript)

²  High-levelProgramminglanguageAPI(Java,Python)

² MobileOSAPI(Android,iOS)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

APIs for Loca,on-based services

41

q  Besidetheservicesdefinedabove,theGoogleMapsJavascriptAPIallowsaddingamapandcustomizingit.

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

<script>functioninitMap(){varmapDiv=document.getElementById('map');varmap=newgoogle.maps.Map(mapDiv,{center:{lat:44.540,lng:-78.546},zoom:8});}</script>

APIs for Loca,on-based services

42

q  MapcustomizaEonsprovidedbytheJavascriptAPI

²  ApplystylestofeatureTypesofthemap²  Addmarkerstothemap²  Customizemarkericons²  Createacustomlegend²  LoaddatausingGeoJSON²  Addheatmaps²  Handleuser’sevents(e.g.clickonthemap)²  …

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

APIs for Loca,on-based services

43

q  GoogleMapsAPI

²  HTTP-basedWebserviceAPI

² WebclientAPI(Javascript)

²  High-levelProgramminglanguageAPI(Java,Python)

² MobileOSAPI(Android,iOS)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

APIs for Loca,on-based services

44APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICES

MARCODIFELICE

h"ps://github.com/googlemaps/google-maps-services-java²  JavaClientforGoogleMapsServices

²  PythonClientforGoogleMapsServicesh"ps://github.com/googlemaps/google-maps-services-python/

²  GOClientforGoogleMapsServicesh"ps://github.com/googlemaps/google-maps-services-go/

APIs for Loca,on-based services

45

q  GoogleMapsAPI

²  HTTP-basedWebserviceAPI

² WebclientAPI(Javascript)

²  High-levelProgramminglanguageAPI(Java,Python)

² MobileOSAPI(Android,iOS)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

APIs for Loca,on-based services

46APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICES

MARCODIFELICE

HOWtogetthecurrentposiEoninAndroid?

LOCATIONMANAGER

GPSprovider Wi-Fiprovider Cellularprovider

LOCATIONLISTENER

LocaRonchanged!

[interface]

NETWORKPROVIDER

APIs for Loca,on-based services

47

q  FusedlocaEonproviderisoneofthelocaRonAPIsinGooglePlayservicesforAndroiddevices.²  Itmanages/hidestheunderlyinglocaRontechnology(i.e.GPS,

cellularbasedorWiFibased).²  Itallowstheusertospecifyrequirementsatahighlevel,like

highaccuracyorlowpower.²  ItallowsopRmizingtheuRlizaRonofthemobiledevice’sba"ery

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKp://developer.android.com/training/locaEon/index.html

APIs for Loca,on-based services

48

q  STEP1-RequestlocaEonpermissions

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

<manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.google.android.gms.location.sample.basiclocationsample"><uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION"/><uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/></manifest>

ANDROIDMANIFEST.XML

DocumentaRonandsourcecodeavailableat:hKp://developer.android.com/training/locaEon/index.html

APIs for Loca,on-based services

49

q  STEP2–ConnecttoGooglePlayservices

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

if(mGoogleApiClient==null){mGoogleApiClient=newGoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build();}…mGoogleApiClient.connect();

DocumentaRonandsourcecodeavailableat:hKp://developer.android.com/training/locaEon/index.html

APIs for Loca,on-based services

50

q  STEP3–GetthelastknownlocaRon

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

publicvoidonConnected(BundleconnectionHint){mLastLocation=

LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);if(mLastLocation!=null){

mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));}}

DocumentaRonandsourcecodeavailableat:hKp://developer.android.com/training/locaEon/index.html

APIs for Loca,on-based services

51

q  STEP4–CreatealocaRonrequest

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

LocationRequestmLocationRequest=newLocationRequest();mLocationRequest.setInterval(10000);mLocationRequest.setFastestInterval(5000);mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

LocationSettingsRequest.Builderbuilder=newLocationSettingsRequest.Builder().addLocationRequest(mLocationRequest);

Interval–inmilliseconds-ofupdates

PRIORITY_BALANCED_POWER_ACCURACY,PRIORITY_HIGH_ACCURACY,PRIORITY_LOW_POWER,PRIORITY_NO_POWER

DocumentaRonandsourcecodeavailableat:hKp://developer.android.com/training/locaEon/index.html

APIs for Loca,on-based services

52

q  STEP5–ReceiveLocaRonupdates

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest,this);

publicclassMainActivityextendsActionBarActivityimplementsConnectionCallbacks,OnConnectionFailedListener,LocationListener{...@OverridepublicvoidonLocationChanged(Locationlocation){mCurrentLocation=location;

…}

DocumentaRonandsourcecodeavailableat:hKp://developer.android.com/training/locaEon/index.html

APIs for Loca,on-based services

53

q  Geofencingisatechniquetodefinevirtualboundariesofageographicarea,andtolocalizeauseroverit.

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

Geofenceàpoint(laRtude/longitude)plusaradiusAneventistriggeredeachRmetheuserentersorexitsthegeofence,ordwellslongerthanagivenintervalofRme.EachgeofenceisassociatedtoanexpiraRonRme

DocumentaRonandsourcecodeavailableat:hKp://developer.android.com/training/locaEon/index.html

APIs for Loca,on-based services

54

q  STEP1–Createageofenceobject

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

mGeofenceList.add(newGeofence.Builder()//SettherequestIDofthegeofence..setRequestId(entry.getKey()).setCircularRegion(entry.getValue().latitude,entry.getValue().longitude,Constants.GEOFENCE_RADIUS_IN_METERS).setExpirationDuration(Constants.GEOFENCE_EXPIRATION_IN_MILLISECONDS).setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER|Geofence.GEOFENCE_TRANSITION_EXIT).build());

DocumentaRonandsourcecodeavailableat:hKp://developer.android.com/training/locaEon/index.html

APIs for Loca,on-based services

55

q  STEP2–DefinetheiniRaltriggerevents

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

mGeofenceList.add(newGeofence.Builder()//SettherequestIDofthegeofence..setRequestId(entry.getKey()).setCircularRegion(entry.getValue().latitude,entry.getValue().longitude,Constants.GEOFENCE_RADIUS_IN_METERS).setExpirationDuration(Constants.GEOFENCE_EXPIRATION_IN_MILLISECONDS).setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER|Geofence.GEOFENCE_TRANSITION_EXIT).build());

DocumentaRonandsourcecodeavailableat:hKp://developer.android.com/training/locaEon/index.html

APIs for Loca,on-based services

56

q  STEP3–AddgeofencesandIntents

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

LocationServices.GeofencingApi.addGeofences(mGoogleApiClient,mGeofenceList,getGeofencePendingIntent())

privatePendingIntentgetGeofencePendingIntent(){Intentintent=newIntent(this,GeofenceTransitionsIntentService.class);returnPendingIntent.getService(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);}

DocumentaRonandsourcecodeavailableat:hKp://developer.android.com/training/locaEon/index.html

APIs for Indoor Localiza,on

57

q  IndoorAtlas(hKps://www.indooratlas.com)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

SDKavailableat:hKps://www.indooratlas.com

q LocalizaRonbygeomagneEctechnology(i.e.analysisoftheEarth’smagneRcfield)

q SupportsindoornavigaRon,geo-fencingandway-finding.

APIs for Indoor Localiza,on

58

q  IndoorAtlas(hKps://www.indooratlas.com)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

SDKavailableat:hKps://www.indooratlas.com

q Client-serverarchitecture,basedonfoursteps

1.  CreateLocaRonandAddmapfloor(throughaWebapplicaRon)

2.  Setwaypoints(throughamobileapp)3.  Walkthroughthewaypoints,andautomaRcally

gathersensordata(e.g.magnetometer)4.  Importthemap,andaddlocaRon-based

featurestoamobileapplicaRon

APIs for Indoor Localiza,on

59

q  IndoorAtlas(hKps://www.indooratlas.com)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

SDKavailableat:hKps://www.indooratlas.com

q SDKforAndroidandIOSoperaRngsystemsLocaRonupdatesareprovidedbytheIALoca/onListenerinterfaceandtheonLoca/onChanged()callbackmethod,andareexpressedasabsolutecoordinates(LAT;LONG).

privateIALocationListenermIALocationListener=newIALocationListener(){@OverridepublicvoidonLocationChanged(IALocationlocation){

Log.d(TAG,"Latitude:"+location.getLatitude());Log.d(TAG,"Longitude:"+location.getLongitude());

}};

APIs for Indoor Localiza,on

60

q  I-Locate(hKp://www.i-locate.eu/the-virtual-hub/)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

FurtherinformaRonavailableat:hKp://www.i-locate.eu/the-virtual-hub/

q EuropeanprojectsaimedatcreaRngapublicgeo-portalforopenindoorgeographicalinformaRon,andatdevelopingthetoolkitforindoor-outdoorlocaRonbasedservices.

Architectureofthetoolkit

APIs for Indoor Localiza,on

61

q  I-Locate(hKp://www.i-locate.eu/the-virtual-hub/)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

FurtherinformaRonavailableat:hKp://www.i-locate.eu/the-virtual-hub/

VIRTUALHUBo  Indoorgeodatao  foraround40

locaRons

o  IntegrablewithOpenStreetMap

o  IndoorML

APIs for Indoor Localiza,on

62

q  ESTIMOTE(hKp://www.i-locate.eu/the-virtual-hub/)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

FurtherinformaRonavailableat:hKp://developer.esEmote.com/android/

Android/IOSSDKforindoorlocalizaRonandLocalizaEonbasedservicesthroughBeaconsq Defineindoorgeofenceregions

q MonitortheBLEsignal

q TriggercorrespondingacRonbasedondetectedBeacon

APIs for Indoor Localiza,on

63

q  ESTIMOTE(hKp://www.i-locate.eu/the-virtual-hub/)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

FurtherinformaRonavailableat:hKp://developer.esEmote.com/android/

EachBeaconisidenRfiedbythreevalues:

²  UUID,commonlyrepresentedasastring,e.g.“B9407F30-F5F8-466E-AFF9-25556B57FE6D”

²  majornumber,anunsignedshortinteger,i.e.,anintegerrangingfrom1to65535,(0isareservedvalue)

²  minornumber,alsoanunsignedshortinteger,likethemajornumber.

APIs for Indoor Localiza,on

64

q  ESTIMOTE(hKp://www.i-locate.eu/the-virtual-hub/)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

FurtherinformaRonavailableat:hKp://developer.esEmote.com/android/

beaconManager=newBeaconManager(getApplicationContext());//addthisbelow:beaconManager.connect(newBeaconManager.ServiceReadyCallback(){@OverridepublicvoidonServiceReady(){beaconManager.startMonitoring(newRegion("monitoredregion",UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D"),22504,48827));}});

DEFINETHEREGION

APIs for Indoor Localiza,on

65

q  ESTIMOTE(hKp://www.i-locate.eu/the-virtual-hub/)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

FurtherinformaRonavailableat:hKp://developer.esEmote.com/android/

beaconManager.setMonitoringListener(newBeaconManager.MonitoringListener(){@OverridepublicvoidonEnteredRegion(Regionregion,List<Beacon>list){ DOSOMETHING}@OverridepublicvoidonExitedRegion(Regionregion){ DOSOMETHING}});

DEFINETHEACTION

APIs for Loca,on-based services

66

q  APIsforHumanacEvityrecogniEonü  Recognizedcategories:VEHICLE,BYCICLE,FOOT,

RUNNING,STILL,TILTING,WALKING

ü  APIsmightreturnmorethanoneclass,plusaconfidencevalue.

ü  DonotrequiretheInternetconnecRvity(?)ü  DonotrequiretheuRlizaRonofGPS(?)

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

DocumentaRonandsourcecodeavailableat:hKp://developer.android.com/training/locaEon/index.html

APIs for Loca,on-based services

67

q  STEP1–RequestAcEvityRecogniEonpermissions

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

<manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.google.android.gms.location.sample.basiclocationsample”><uses-permissionandroid:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>…

ANDROIDMANIFEST.XML

Amongtheothers,atutorialisavailableat:hKp://code.tutsplus.com/tutorials/how-to-recognize-user-acEvity-with-acEvity-recogniEon--cms-25851

APIs for Loca,on-based services

68

q  STEP2–ConnecttotheGooglePlayAPI

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

mApiClient=newGoogleApiClient.Builder(this).addApi(ActivityRecognition.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();mApiClient.connect();

Amongtheothers,atutorialisavailableat:hKp://code.tutsplus.com/tutorials/how-to-recognize-user-acEvity-with-acEvity-recogniEon--cms-25851

APIs for Loca,on-based services

69

q  STEP3–IssueanacEvityrecogniEonrequest

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

Intentintent=newIntent(this,ActivityRecognizedService.class);PendingIntentpendingIntent=PendingIntent.getService(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(mApiClient,3000,pendingIntent);

INTERVALAMONGCONSECUTIVEREQUESTS

Amongtheothers,atutorialisavailableat:hKp://code.tutsplus.com/tutorials/how-to-recognize-user-acEvity-with-acEvity-recogniEon--cms-25851

APIs for Loca,on-based services

70

q  STEP4–ParseacEvityrecogniEonresults

APPLICATIONLAYERINTERFACES(API)FORLOCATION-BASEDSERVICESMARCODIFELICE

ActivityRecognitionResultresult=ActivityRecognitionResult.extractResult(intent);List<DetectedActivity>probableActivities=result.getProbableActivities();

for(DetectedActivityactivity:probableActivities){switch(activity.getType()){caseDetectedActivity.IN_VEHICLE:{Log.e("ActivityRecogition","InVehicle:"+

activity.getConfidence());break;}

Amongtheothers,atutorialisavailableat:hKp://code.tutsplus.com/tutorials/how-to-recognize-user-acEvity-with-acEvity-recogniEon--cms-25851