Geolocation: What You Need to Know

 
SE-2840 Dr. Mark L. Hornick
 
1
 
G
e
o
l
o
c
a
t
i
o
n
 
Wherever you go, there you are
 
W
h
a
t
 
i
s
 
G
e
o
l
o
c
a
t
i
o
n
?
 
Built-in browser functionality that lets you
make a web application location-aware
Geographic latitude/longitude
 
Supported by all modern browsers
Geolocation services are part of the
HTML5/W3C JavaScript API
 
SE-2840 Dr. Mark L. Hornick
 
2
 
W
h
a
t
 
c
a
n
 
y
o
u
 
d
o
 
w
i
t
h
G
e
o
l
o
c
a
t
i
o
n
?
 
Show user’s position on a map
Indicate proximity to hospitals, coffee shops,
public transit…
Provide directions to a known point of interest
Alert users to friends in the area
Notify users of events, traffic, local weather…
Provide auto-assist for zip code, area code,
shipping costs…
 
SE-2840 Dr. Mark L. Hornick
 
3
 
H
o
w
 
d
o
e
s
 
t
h
e
 
b
r
o
w
s
e
r
 
k
n
o
w
y
o
u
r
 
l
o
c
a
t
i
o
n
?
 
 
First, the browser must obtain your consent to
use your location
This security mechanism is built-in and cannot be
disabled (part of HTML5 specification)
Next, the browser gathers information from
your computer
Collected info is sent to the default location service
provider (Google Location Services) to get an
estimate of your location
 
SE-2840 Dr. Mark L. Hornick
 
4
 
L
o
c
a
t
i
o
n
 
o
n
 
s
t
a
t
i
o
n
a
r
y
d
e
s
k
t
o
p
 
c
o
m
p
u
t
e
r
s
 
 
Location information generally available to the
browser is limited to the IP address supplied by
your ISP
Universally available on any computer
Often resolves to your ISP’s office location, so accurate
only to a neighborhood or city
Limits what you can do with the information
Local weather forecast
Default language to present to user
 
SE-2840 Dr. Mark L. Hornick
 
5
 
W
i
f
i
-
b
a
s
e
d
 
g
e
o
l
o
c
a
t
i
o
n
 
Google (and others) have an extensive
database of wifi networks that were collected
as part of the Google Maps project
If multiple wifi hotspots are available,
triangulation based on signal strength can be
used to determine location to ~100 ft
Relies on accuracy of the database
 
SE-2840 Dr. Mark L. Hornick
 
6
 
C
e
l
l
p
h
o
n
e
-
b
a
s
e
d
 
g
e
o
l
o
c
a
t
i
o
n
 
Cell towers report their geographical location
to the device using the tower
When multiple cell towers are available,
triangulation based on signal strength can be
used to determine location
Fairly accurate (~100ft)
Works indoors and outdoors
In (rural) areas with few cell towers, accuracy
is poor
 
SE-2840 Dr. Mark L. Hornick
 
7
 
G
P
S
-
b
a
s
e
d
 
g
e
o
l
o
c
a
t
i
o
n
 
Device hosting the browser contains
hardware that receives signals from multiple
GPS satellites in geosynchronous orbit
Can be highly accurate (~3ft)
Available everywhere
Works outdoors only – view of sky required
Accuracy decreases in areas with tall buildings,
forests, cloudy skies, sunspot activity
 
SE-2840 Dr. Mark L. Hornick
 
8
 
H
o
w
 
d
o
 
y
o
u
 
s
e
l
e
c
t
 
w
h
i
c
h
m
e
t
h
o
d
 
y
o
u
r
 
b
r
o
w
s
e
r
 
w
i
l
l
 
u
s
e
?
 
Y
o
u
 
d
o
n
t
 
 
t
h
e
 
b
r
o
w
s
e
r
 
w
i
l
l
 
d
e
c
i
d
e
 
i
n
t
e
r
n
a
l
l
y
h
o
w
 
i
t
 
i
s
 
g
o
i
n
g
 
t
o
 
d
e
t
e
r
m
i
n
e
 
y
o
u
r
 
l
o
c
a
t
i
o
n
.
However, you can specify how accurate you
want the answer to be
The browser may communicate with your device
to prompt you to enable GPS (if you have it) to
get you a more accurate estimate of your location.
 
SE-2840 Dr. Mark L. Hornick
 
9
 
B
O
M
 
i
m
p
l
e
m
e
n
t
a
t
i
o
n
:
 
G
e
o
l
o
c
a
t
i
o
n
 
s
e
r
v
i
c
e
s
a
r
e
 
p
a
r
t
 
o
f
 
t
h
e
 
n
a
v
i
g
a
t
o
r
 
c
h
i
l
d
 
o
b
j
e
c
t
 
o
f
 
t
h
e
w
i
n
d
o
w
 
o
b
j
e
c
t
 
SE-2840
Dr. Mark L. Hornick
 
10
 
 
The geolocation API methods are
implemented in the navigator
object.
 
If geolocation is not supported,
the navigator object will not have
a geolocation child object.
geolocation
 
 
 
SE-2840 Dr. Mark L. Hornick
 
11
 
G
e
o
l
o
c
a
t
i
o
n
 
J
a
v
a
S
c
r
i
p
t
 
A
P
I
:
g
e
t
t
i
n
g
 
y
o
u
r
 
l
o
c
a
t
i
o
n
 
 
One-time position request:
 
if( navigator.geolocation ) {
// check for geolocation support
 
    navigator.geolocation.getCurrentPosition( 
displayLoc 
);
 
} else { 
// no geolocation object in BOM navigator
  
alert(“No geolocation support!”);
 
}
...
 
// This function is called when the location is found
 
function 
displayLoc
( position ) {
  
var lat = position.coords.latitude;
  
var long = position.coords.longitude;
  
// TODO: display the position somewhere on the page
 
}
 
 
 
SE-2840
Dr. Mark L. Hornick
 
12
 
g
e
t
C
u
r
r
e
n
t
P
o
s
i
t
i
o
n
(
)
 
d
e
t
a
i
l
s
 
h
a
n
d
l
i
n
g
 
e
r
r
o
r
s
 
 
getCurrentPosition takes 1, 2, or 3 arguments:
 
getCurrentPosition( 
successHandler,
    
 
/* optional */ 
errorHandler,
    
 
/* optional */ 
positionOptions
);
 
// This function is called when an error occurs:
 
function 
errorHandler
( error ) {
  
// error.code is a value from 0 – 3:
  
// 0: unknown error
  
// 1: Permission denied by user
  
// 2: position not available
  
// 3: request timed out
 
// if the error code is 0 or 2, error.message may
 
// contain a more specific reason for the failure
 
}
 
 
 
SE-2840
Dr. Mark L. Hornick
 
13
 
G
e
o
l
o
c
a
t
i
o
n
 
J
a
v
a
S
c
r
i
p
t
 
A
P
I
w
a
t
c
h
i
n
g
 
y
o
u
r
 
l
o
c
a
t
i
o
n
 
c
h
a
n
g
e
 
 
Periodic update position request:
 
if( navigator.geolocation ) {
// check for geolocation support
 
    
wID
 = navigator.geolocation.watchPosition( 
displayLoc 
);
 
} else { 
// no geolocation object in BOM navigator
  
alert(“No geolocation support!”);
 
}
 
// Call this function to cancel the watch
 
function 
stopWatch
() {
  
if( 
wID
 ) {
 
// make sure wID is not null
   
navigator.geolocation.clearWatch( wID );
   
wID = null;
  
}
 
}
 
 
 
SE-2840
Dr. Mark L. Hornick
 
14
 
p
o
s
i
t
i
o
n
O
p
t
i
o
n
s
 
d
e
t
a
i
l
s
 
 
c
h
a
n
g
i
n
g
h
o
w
 
o
f
t
e
n
 
y
o
u
r
 
l
o
c
a
t
i
o
n
 
i
s
 
u
p
d
a
t
e
d
 
B
o
t
h
 
g
e
t
C
u
r
r
e
n
t
P
o
s
i
t
i
o
n
 
 
a
n
d
 
w
a
t
c
h
P
o
s
i
t
i
o
n
 
t
a
k
e
 
a
n
 
o
p
t
i
o
n
a
l
3
r
d
 
P
o
s
i
t
i
o
n
O
p
t
i
o
n
s
 
a
r
g
u
m
e
n
t
.
 
getCurrentPosition( 
successHandler,
    
 
/* optional */ 
errorHandler,
    
 
/* optional */ 
positionOptions
);
 
// The positionOptions argument is a map:
 
var 
positionOptions
 {
  
enableHighAccuracy: true, 
// favor accuracy over speed
  
timeout: Infinity, 
// ms to wait for pos value
  
maximumAge: 0
 
      
// ms age of cached pos; 0=get new pos
 
}
 
 
 
SE-2840
Dr. Mark L. Hornick
 
15
 
 
SE-2840 Dr. Mark L. Hornick
 
16
Slide Note
Embed
Share

Geolocation is a built-in browser functionality that allows web applications to be location-aware. It uses geographic latitude/longitude and is supported by all modern browsers, making it an integral part of the HTML5/W3C JavaScript API. With geolocation, you can show users their position on a map, provide directions to points of interest, alert users to nearby places of interest, and more. The browser obtains user consent before using their location data and can determine location through IP addresses, wifi networks, or cell towers. Learn how geolocation enhances user experiences and enables various features on the web.

  • Geolocation
  • Browser Functionality
  • Location Awareness
  • Web Applications
  • HTML5

Uploaded on Aug 30, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Geolocation Wherever you go, there you are SE-2840 Dr. Mark L. Hornick 1

  2. What is Geolocation? Built-in browser functionality that lets you make a web application location-aware Geographic latitude/longitude Supported by all modern browsers Geolocation services are part of the HTML5/W3C JavaScript API SE-2840 Dr. Mark L. Hornick 2

  3. What can you do with Geolocation? Show user s position on a map Indicate proximity to hospitals, coffee shops, public transit Provide directions to a known point of interest Alert users to friends in the area Notify users of events, traffic, local weather Provide auto-assist for zip code, area code, shipping costs SE-2840 Dr. Mark L. Hornick 3

  4. How does the browser know your location? First, the browser must obtain your consent to use your location This security mechanism is built-in and cannot be disabled (part of HTML5 specification) Next, the browser gathers information from your computer Collected info is sent to the default location service provider (Google Location Services) to get an estimate of your location SE-2840 Dr. Mark L. Hornick 4

  5. Location on stationary desktop computers Location information generally available to the browser is limited to the IP address supplied by your ISP Universally available on any computer Often resolves to your ISP s office location, so accurate only to a neighborhood or city Limits what you can do with the information Local weather forecast Default language to present to user SE-2840 Dr. Mark L. Hornick 5

  6. Wifi-based geolocation Google (and others) have an extensive database of wifi networks that were collected as part of the Google Maps project If multiple wifi hotspots are available, triangulation based on signal strength can be used to determine location to ~100 ft Relies on accuracy of the database SE-2840 Dr. Mark L. Hornick 6

  7. Cellphone-based geolocation Cell towers report their geographical location to the device using the tower When multiple cell towers are available, triangulation based on signal strength can be used to determine location Fairly accurate (~100ft) Works indoors and outdoors In (rural) areas with few cell towers, accuracy is poor SE-2840 Dr. Mark L. Hornick 7

  8. GPS-based geolocation Device hosting the browser contains hardware that receives signals from multiple GPS satellites in geosynchronous orbit Can be highly accurate (~3ft) Available everywhere Works outdoors only view of sky required Accuracy decreases in areas with tall buildings, forests, cloudy skies, sunspot activity SE-2840 Dr. Mark L. Hornick 8

  9. How do you select which method your browser will use? You don t the browser will decide internally how it is going to determine your location. However, you can specify how accurate you want the answer to be The browser may communicate with your device to prompt you to enable GPS (if you have it) to get you a more accurate estimate of your location. SE-2840 Dr. Mark L. Hornick 9

  10. BOM implementation: Geolocation services are part of the navigator child object of the window object The geolocation API methods are implemented in the navigator object. geolocation If geolocation is not supported, the navigator object will not have a geolocation child object. SE-2840 10 Dr. Mark L. Hornick

  11. SE-2840 Dr. Mark L. Hornick 11

  12. Geolocation JavaScript API: getting your location One-time position request: if( navigator.geolocation ) {// check for geolocation support navigator.geolocation.getCurrentPosition( displayLoc ); } else { // no geolocation object in BOM navigator alert( No geolocation support! ); } ... // This function is called when the location is found function displayLoc( position ) { var lat = position.coords.latitude; var long = position.coords.longitude; // TODO: display the position somewhere on the page } SE-2840 Dr. Mark L. Hornick 12

  13. getCurrentPosition() details handling errors getCurrentPosition takes 1, 2, or 3 arguments: getCurrentPosition( successHandler, /* optional */ errorHandler, /* optional */ positionOptions); // This function is called when an error occurs: function errorHandler( error ) { // error.code is a value from 0 3: // 0: unknown error // 1: Permission denied by user // 2: position not available // 3: request timed out // if the error code is 0 or 2, error.message may // contain a more specific reason for the failure } SE-2840 13 Dr. Mark L. Hornick

  14. Geolocation JavaScript API watching your location change Periodic update position request: if( navigator.geolocation ) {// check for geolocation support wID = navigator.geolocation.watchPosition( displayLoc ); } else { // no geolocation object in BOM navigator alert( No geolocation support! ); } // Call this function to cancel the watch function stopWatch() { if( wID ) { // make sure wID is not null navigator.geolocation.clearWatch( wID ); wID = null; } } SE-2840 Dr. Mark L. Hornick 14

  15. positionOptions details changing how often your location is updated Both getCurrentPosition and watchPosition take an optional 3rdPositionOptions argument. getCurrentPosition( successHandler, /* optional */ errorHandler, /* optional */ positionOptions); // The positionOptions argument is a map: var positionOptions { enableHighAccuracy: true, // favor accuracy over speed timeout: Infinity, // ms to wait for pos value maximumAge: 0 // ms age of cached pos; 0=get new pos } SE-2840 15 Dr. Mark L. Hornick

  16. SE-2840 Dr. Mark L. Hornick 16

Related


More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#