SlideShare a Scribd company logo
HTML Geolocation
API
AWT Activity 1
Presented By:
A Vaibhav Jain, Suman Garai, Arvind Kumar, Subharanjan
Agenda
What is Geolocation
Supported Browsers
HTML Geolocation Implementation
Example Code
Error Handling
Example Code
Demo
Other interesting methods
3/24/2023 2
What is Geolocation?
• Geolocation refers to the geographical (latitudinal and longitudinal)
location of an Internet-connected device.
• Not your location, mind you, but the location of whatever electronic
medium is being used to access the Internet.
• Geolocation data can be collected on various basis, like, Device
based, Server Based, Hybrid.
3/24/2023 3
Supported Browsers
Above table shows the supported
browsers that supports
geolocation API.
HTML Geolocation
Implementation
3/24/2023 5
In order to implement the API, we must use the ‘navigator’ class of JavaScript, which
return the Geolocation object that gives web content access to the location of the
device.
Logic to implement the API:
• Check if Geolocation is supported.
• If supported, call the getCurrentPosition() method. Else, display error message.
• If the getCurrentPosition(parameter: showPosition) is called successfully, it
returns the coordinates object to the function specified in the parameter.
• The method showPosition() outputs the Latitude and Longitude.
getCurrentPosition() method accepts two parameters, first being, showPosition() and
the second is, showError()
Example Code
3/24/2023 6
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude +
"<br>Accuracy: " + position.coords.accuracy;
}
</script>
Error Handling
• As the second parameter, the getCurrentPosition() accepts
showError() method.
• This is used to handle errors. It specifies a function to run if it fails
to get the user’s location values.
• This method contains a set of possible errors that might occur while
accessing a user’s location are given below:
• Error.PERMISSION_DENIED
• Error.POSITION_UNAVAILABLE
• Error.TIMEOUT
• Error.UNKNOWN_ERROR
3/24/2023 7
Example Code
3/24/2023 8
<script>
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML = "An unknown error occurred."
break;
}
}
<script>
Return Data - getCurrentPosition()
Method
3/24/2023 9
Property Returns
coords.latitude The latitude as a decimal number (always returned)
coords.longitude The longitude as a decimal number (always returned)
coords.accuracy The accuracy of position (always returned)
coords.altitude The altitude in meters above the mean sea level (returned if
available)
coords.altitudeAccuracy The altitude accuracy of position (returned if available)
coords.heading The heading as degrees clockwise from North (returned if
available)
coords.speed The speed in meters per second (returned if available)
timestamp The date/time of the response (returned if available)
Demo
Click here to see the demo
3/24/2023 10
Screenshot of the program
3/24/2023 11
Other Interesting Methods
watchPosition()
Returns the current position of the
user and continues to return
updated position as the user
moves.
Syntax :
navigator.geolocation.watchPosi
tion(showPosition);
clearWatch()
3/24/2023 PRESENTATION TITLE 12
Stops the watchPosition() method.
Syntax:
navigator.geolocation.clearWacth();
Thank you

More Related Content

PPTX
Html 5 geolocation api
PPTX
Geoloaction
PPTX
PPTX
W3 c geolocation api
PDF
Geolocation and mapping using Google Maps services
PDF
Mobile geolocation and mapping
PDF
Introduction to Map and Location APIs (Silicon Valley Code Camp 2017)
PDF
Introduction to Map and Location APIs (Silicon Valley Code Camp 2017)
Html 5 geolocation api
Geoloaction
W3 c geolocation api
Geolocation and mapping using Google Maps services
Mobile geolocation and mapping
Introduction to Map and Location APIs (Silicon Valley Code Camp 2017)
Introduction to Map and Location APIs (Silicon Valley Code Camp 2017)

Similar to 20220816-GeolocationAPI-AdvancedWebDevelopment.pptx (13)

KEY
Location, location, geolocation
PDF
[2015/2016] Geolocation and mapping
ODP
Location Aware Browsing
PDF
A Comprehensive Guide Unlocking the Power of IP Geolocation API 2024.pdf
PDF
Geolocation and Mapping
PDF
Where 2.0 2009 - Location on the Web
KEY
W3C Geolocation
PPTX
U3-03-Google Location Based Services.pptx
PDF
How to use geolocation in react native apps
PDF
Data for Happiness Hackathon 2018 Dubai
PDF
Data for Happiness Hackathon 2018 Dubai
PPTX
Geolocation
PDF
Geolocation and Mapping in PhoneGap applications
Location, location, geolocation
[2015/2016] Geolocation and mapping
Location Aware Browsing
A Comprehensive Guide Unlocking the Power of IP Geolocation API 2024.pdf
Geolocation and Mapping
Where 2.0 2009 - Location on the Web
W3C Geolocation
U3-03-Google Location Based Services.pptx
How to use geolocation in react native apps
Data for Happiness Hackathon 2018 Dubai
Data for Happiness Hackathon 2018 Dubai
Geolocation
Geolocation and Mapping in PhoneGap applications
Ad

More from Suman Garai (13)

PDF
mastersDegree-finalYearProject-ClinicalGPT
PDF
Hidden in Plain Sight: Securing Digital Secrets with Image Steganography
PDF
20230513-reconFTW-CyberSapiens.pdf
PDF
20230324-Exploring the Landscape of Password Managers for Individual Users a...
PDF
20230105-TestCases&Oracle-MobileTesting.pdf
PDF
20221003-DigitalForensicTools-DigitalForensicInvestigation.pdf
PPTX
20220911-ISO27000-SecurityStandards.pptx
PPTX
20220819-Ecosystem-EnviornmentalScience.pptx
PPTX
20220728-iOSAppDev-MobileAppDev.pptx
PPSX
20210906-Nessus-FundamentalInfoSec.ppsx
PPSX
20210727-Technoprenuership-EntreprenuershipDev.ppsx
PPTX
20210717-AntiBotnets-FundamentalInfoSec.pptx
PPTX
20210417-cppRelevancy-DataStructures.pptx
mastersDegree-finalYearProject-ClinicalGPT
Hidden in Plain Sight: Securing Digital Secrets with Image Steganography
20230513-reconFTW-CyberSapiens.pdf
20230324-Exploring the Landscape of Password Managers for Individual Users a...
20230105-TestCases&Oracle-MobileTesting.pdf
20221003-DigitalForensicTools-DigitalForensicInvestigation.pdf
20220911-ISO27000-SecurityStandards.pptx
20220819-Ecosystem-EnviornmentalScience.pptx
20220728-iOSAppDev-MobileAppDev.pptx
20210906-Nessus-FundamentalInfoSec.ppsx
20210727-Technoprenuership-EntreprenuershipDev.ppsx
20210717-AntiBotnets-FundamentalInfoSec.pptx
20210417-cppRelevancy-DataStructures.pptx
Ad

Recently uploaded (20)

PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PPTX
E -tech empowerment technologies PowerPoint
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
PPTX
IPCNA VIRTUAL CLASSES INTERMEDIATE 6 PROJECT.pptx
PDF
The Evolution of Traditional to New Media .pdf
PDF
Exploring VPS Hosting Trends for SMBs in 2025
PDF
mera desh ae watn.(a source of motivation and patriotism to the youth of the ...
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PDF
Uptota Investor Deck - Where Africa Meets Blockchain
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PPT
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt
PPTX
Database Information System - Management Information System
PPT
250152213-Excitation-SystemWERRT (1).ppt
DOC
Rose毕业证学历认证,利物浦约翰摩尔斯大学毕业证国外本科毕业证
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
📍 LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1 TERPOPULER DI INDONESIA ! 🌟
PPTX
1402_iCSC_-_RESTful_Web_APIs_--_Josef_Hammer.pptx
PPTX
Mathew Digital SEO Checklist Guidlines 2025
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
E -tech empowerment technologies PowerPoint
Design_with_Watersergyerge45hrbgre4top (1).ppt
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
IPCNA VIRTUAL CLASSES INTERMEDIATE 6 PROJECT.pptx
The Evolution of Traditional to New Media .pdf
Exploring VPS Hosting Trends for SMBs in 2025
mera desh ae watn.(a source of motivation and patriotism to the youth of the ...
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Uptota Investor Deck - Where Africa Meets Blockchain
Power Point - Lesson 3_2.pptx grad school presentation
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt
Database Information System - Management Information System
250152213-Excitation-SystemWERRT (1).ppt
Rose毕业证学历认证,利物浦约翰摩尔斯大学毕业证国外本科毕业证
SAP Ariba Sourcing PPT for learning material
📍 LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1 TERPOPULER DI INDONESIA ! 🌟
1402_iCSC_-_RESTful_Web_APIs_--_Josef_Hammer.pptx
Mathew Digital SEO Checklist Guidlines 2025
The New Creative Director: How AI Tools for Social Media Content Creation Are...

20220816-GeolocationAPI-AdvancedWebDevelopment.pptx

  • 1. HTML Geolocation API AWT Activity 1 Presented By: A Vaibhav Jain, Suman Garai, Arvind Kumar, Subharanjan
  • 2. Agenda What is Geolocation Supported Browsers HTML Geolocation Implementation Example Code Error Handling Example Code Demo Other interesting methods 3/24/2023 2
  • 3. What is Geolocation? • Geolocation refers to the geographical (latitudinal and longitudinal) location of an Internet-connected device. • Not your location, mind you, but the location of whatever electronic medium is being used to access the Internet. • Geolocation data can be collected on various basis, like, Device based, Server Based, Hybrid. 3/24/2023 3
  • 4. Supported Browsers Above table shows the supported browsers that supports geolocation API.
  • 5. HTML Geolocation Implementation 3/24/2023 5 In order to implement the API, we must use the ‘navigator’ class of JavaScript, which return the Geolocation object that gives web content access to the location of the device. Logic to implement the API: • Check if Geolocation is supported. • If supported, call the getCurrentPosition() method. Else, display error message. • If the getCurrentPosition(parameter: showPosition) is called successfully, it returns the coordinates object to the function specified in the parameter. • The method showPosition() outputs the Latitude and Longitude. getCurrentPosition() method accepts two parameters, first being, showPosition() and the second is, showError()
  • 6. Example Code 3/24/2023 6 <script> function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { x.innerHTML = "Geolocation is not supported by this browser."; } } function showPosition(position) { x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude + "<br>Accuracy: " + position.coords.accuracy; } </script>
  • 7. Error Handling • As the second parameter, the getCurrentPosition() accepts showError() method. • This is used to handle errors. It specifies a function to run if it fails to get the user’s location values. • This method contains a set of possible errors that might occur while accessing a user’s location are given below: • Error.PERMISSION_DENIED • Error.POSITION_UNAVAILABLE • Error.TIMEOUT • Error.UNKNOWN_ERROR 3/24/2023 7
  • 8. Example Code 3/24/2023 8 <script> function showError(error) { switch(error.code) { case error.PERMISSION_DENIED: x.innerHTML = "User denied the request for Geolocation." break; case error.POSITION_UNAVAILABLE: x.innerHTML = "Location information is unavailable." break; case error.TIMEOUT: x.innerHTML = "The request to get user location timed out." break; case error.UNKNOWN_ERROR: x.innerHTML = "An unknown error occurred." break; } } <script>
  • 9. Return Data - getCurrentPosition() Method 3/24/2023 9 Property Returns coords.latitude The latitude as a decimal number (always returned) coords.longitude The longitude as a decimal number (always returned) coords.accuracy The accuracy of position (always returned) coords.altitude The altitude in meters above the mean sea level (returned if available) coords.altitudeAccuracy The altitude accuracy of position (returned if available) coords.heading The heading as degrees clockwise from North (returned if available) coords.speed The speed in meters per second (returned if available) timestamp The date/time of the response (returned if available)
  • 10. Demo Click here to see the demo 3/24/2023 10
  • 11. Screenshot of the program 3/24/2023 11
  • 12. Other Interesting Methods watchPosition() Returns the current position of the user and continues to return updated position as the user moves. Syntax : navigator.geolocation.watchPosi tion(showPosition); clearWatch() 3/24/2023 PRESENTATION TITLE 12 Stops the watchPosition() method. Syntax: navigator.geolocation.clearWacth();