advanced geolocation for the mobile web - esri...2017 esri developer...

46
Advanced Geolocation for the Mobile Web Andy Gup, @agup

Upload: others

Post on 25-Sep-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Advanced Geolocationfor the Mobile Web

Andy Gup, @agup

Page 2: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

How to get a good location

Challenges

Solutions

Page 3: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Smartphone/Tablet GPS

Built for consumer use-cases

Accuracy only needs to be “good enough”

Tiny antenna on bottom of device

Page 4: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Geolocation Object

Page 5: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Say what, 4887 meters accuracy???

Indoors using WiFi-only

Page 6: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Demo

http://github.com/esri/html5-geolocation-tool-js

Page 7: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Best possible accuracy…under perfect conditions

3 – 10 meters

10 – 33 feet

Page 8: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Problem 1: location fluctuations

Page 9: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Problem 2: all locations lumped together

Network location

GPS location

Page 10: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile
Page 11: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile
Page 12: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

??

Page 13: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Use case: Stationary…

5 minutes!

Page 14: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Problem 3: Accuracy will vary

Bad

So-so

GoodTime vs Accuracy

Page 15: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Problem 3: Accuracy will vary

Bad

So-so

GoodTime vs Accuracy

Page 16: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Accuracy vs Precision

Low AccuracyHigh Precision

High AccuracyLow Precision

High AccuracyHigh Precision

Page 17: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Problem 4: GPS needs to warm up!

Initial readings less accurate or non-existent

Page 18: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Technical Use Case: Cold Start

GPS takes time to calibrate

Phone rebooted

Updated phone OS

Potential for no cached values

Potential for large inaccuracy

Page 19: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Technical Use Case: Warm start

GPS has been in use continuouslyGPS is (mostly) calibrated

Highest potential for accuracy and precision

Page 20: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Using the Geolocation API options

errorHandler()

Timeout

maximumAge – used only during startup

enableHighAccuracy

Page 21: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Snapshot location – Not Reliable!

navigator.geolocation.getCurrentPosition();

Page 22: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

watchId = navigator.geolocation.watchPosition(

processGeolocation,

/* OPTIONAL */

geolocationError,

{

timeout: 0,

maximumAge: Infinity,

enableHighAccuracy: true

}

);

Continuous location

Page 23: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

maximumAge (ms)

Max age of cached position in milliseconds

“0” – do not use cache

“Infinity” – (default) return any cached value

Page 24: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

timeout (ms)

Max milliseconds to return a positionThrow error if no location at timeoutWith watchPosition() can throw error repeatedly

“Infinity” – (default) don’t return until position available

Page 25: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

enableHighAccuracy(boolean)

Try to obtain best possible result

If GPS available and perms enabled -- use it

If Geolocation Service available -- use it

– Requires an internet connection!

– WiFi and/or Cellular

Page 26: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

watchPosition scenario 1:

{

timeout: 30000,

maximumAge: 300000

}

Request result < 30 secondsAccept cache value < 5 mins old

Page 27: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

watchPosition scenario 2:

{

timeout: 60000,

maximumAge: Infinity

}

Request result < 1 minuteReturn any cache value

Page 28: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

watchPosition scenario 3:

{

timeout: 60000,

maximumAge: 0,

enableHighAccuracy: true

}

Request result < 1 minuteDo NOT use cache, try GPS

Page 29: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Browser Geolocation AccuracyDepends on …

Type of browserType of deviceWi-Fi On/OffGPS On/OffLocation user permissionsVPN

Page 30: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Force phone to use GPS

Page 31: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Solution 1: Post-process bufferingSolution 2: Cordova pluginSolution 3: 1 and/or 2 + external GPS

Page 32: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Solution 1:Buffering to determine center point

Capture many points

Average all values

Calculate centroid

[{lat:-120,lon:35}, {lat:-120.01,lon:35.1}, {lat:-120.011,lon:35.02}, {lat:-120,lon:35.1}, {lat:-120,lon:35}]

Page 33: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

JavaScriptData Collection

Field location template

github.com/esri/html5-geolocation-tool-js

Page 34: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Solution 2:Cordova/PhoneGap & Geolocation

Taps native SDKs via plugins

Direct access to geolocation functionality

Can track geolocation while in background

Battery usage optimization

Page 35: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

cordova-plugin-advanced-gelocation

https://github.com/Esri/cordova-plugin-advanced-geolocation

Separates GPS from Network location

Multi-threaded for high performance

Calculates centroid

Android only!

Native functionality

Separates network locations

from GPS locations

Page 36: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

External GPS

Can provide greater accuracy and precision

Can provide faster location acquisition

Connect via USB or Bluetooth

Page 37: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Example: Trimble R1Sub-meter accuracy*

Works with Geolocation API

Overrides onboard GPS

Works on iOS and Android

Page 38: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

On extra step on Android

Page 39: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile
Page 40: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

A GPS Experiment

START POINT

Page 41: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Commercial GPS Smartphone GPS

Page 42: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Solution 3: buffer, plugin + external GPS

Take a close look at use casesStudy your requirements

Page 43: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Recap

Consumer vs Commercial case casesConsumer vs Commercial equipment

Accuracy vs Precision

Getting the best static location

Page 44: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Questions?

Andy Gup, Esri Developer Advocatehttp://[email protected]@agup

Page 45: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Works with..

Page 46: Advanced Geolocation for the Mobile Web - Esri...2017 Esri Developer Summit-International--Presentation, 2017 Esri Developer Summit-International, Advanced Geolocation for the Mobile

Works with…