SlideShare ist ein Scribd-Unternehmen logo
1 von 13
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

Weitere ähnliche Inhalte

Ähnlich wie 20220816-GeolocationAPI-AdvancedWebDevelopment.pptx

Android App Development - 14 location, media and notifications
Android App Development - 14 location, media and notificationsAndroid App Development - 14 location, media and notifications
Android App Development - 14 location, media and notificationsDiego Grancini
 
iOS: Frameworks and Delegation
iOS: Frameworks and DelegationiOS: Frameworks and Delegation
iOS: Frameworks and DelegationJussi Pohjolainen
 
12.Maps and Location
12.Maps and Location12.Maps and Location
12.Maps and LocationNguyen Tuan
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication developmentGanesh Gembali
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native appsInnovationM
 
Mobile geolocation and mapping
Mobile geolocation and mappingMobile geolocation and mapping
Mobile geolocation and mappingIvano Malavolta
 
Location-Based Services on Android
Location-Based Services on AndroidLocation-Based Services on Android
Location-Based Services on AndroidJomar Tigcal
 
Mobile Application Development-Lecture 15 & 16.pdf
Mobile Application Development-Lecture 15 & 16.pdfMobile Application Development-Lecture 15 & 16.pdf
Mobile Application Development-Lecture 15 & 16.pdfAbdullahMunir32
 
ADV JAVA UNIT 2 M.SC CS (1).pdf
ADV JAVA UNIT 2 M.SC CS (1).pdfADV JAVA UNIT 2 M.SC CS (1).pdf
ADV JAVA UNIT 2 M.SC CS (1).pdfKALAISELVI P
 
LUMIA APP LABS: HERE MAPS AND LOCATION APIS FOR WINDOWS PHONE
LUMIA APP LABS: HERE MAPS AND LOCATION APIS FOR WINDOWS PHONELUMIA APP LABS: HERE MAPS AND LOCATION APIS FOR WINDOWS PHONE
LUMIA APP LABS: HERE MAPS AND LOCATION APIS FOR WINDOWS PHONEMicrosoft Mobile Developer
 
Mobile applications chapter 6
Mobile applications chapter 6Mobile applications chapter 6
Mobile applications chapter 6Akib B. Momin
 
9781305078444 ppt ch10
9781305078444 ppt ch109781305078444 ppt ch10
9781305078444 ppt ch10Terry Yoast
 
GWT training session 3
GWT training session 3GWT training session 3
GWT training session 3SNEHAL MASNE
 
Windows phone 7 series
Windows phone 7 seriesWindows phone 7 series
Windows phone 7 seriesopenbala
 

Ähnlich wie 20220816-GeolocationAPI-AdvancedWebDevelopment.pptx (20)

Android App Development - 14 location, media and notifications
Android App Development - 14 location, media and notificationsAndroid App Development - 14 location, media and notifications
Android App Development - 14 location, media and notifications
 
iOS: Frameworks and Delegation
iOS: Frameworks and DelegationiOS: Frameworks and Delegation
iOS: Frameworks and Delegation
 
Geolocation and Mapping
Geolocation and MappingGeolocation and Mapping
Geolocation and Mapping
 
12.Maps and Location
12.Maps and Location12.Maps and Location
12.Maps and Location
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication development
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native apps
 
Rmi
RmiRmi
Rmi
 
Mobile geolocation and mapping
Mobile geolocation and mappingMobile geolocation and mapping
Mobile geolocation and mapping
 
Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patt...
Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patt...Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patt...
Chapter 05: Eclipse Vert.x - Service Discovery, Resilience and Stability Patt...
 
Location-Based Services on Android
Location-Based Services on AndroidLocation-Based Services on Android
Location-Based Services on Android
 
Mobile Application Development-Lecture 15 & 16.pdf
Mobile Application Development-Lecture 15 & 16.pdfMobile Application Development-Lecture 15 & 16.pdf
Mobile Application Development-Lecture 15 & 16.pdf
 
ADV JAVA UNIT 2 M.SC CS (1).pdf
ADV JAVA UNIT 2 M.SC CS (1).pdfADV JAVA UNIT 2 M.SC CS (1).pdf
ADV JAVA UNIT 2 M.SC CS (1).pdf
 
LUMIA APP LABS: HERE MAPS AND LOCATION APIS FOR WINDOWS PHONE
LUMIA APP LABS: HERE MAPS AND LOCATION APIS FOR WINDOWS PHONELUMIA APP LABS: HERE MAPS AND LOCATION APIS FOR WINDOWS PHONE
LUMIA APP LABS: HERE MAPS AND LOCATION APIS FOR WINDOWS PHONE
 
Mobile applications chapter 6
Mobile applications chapter 6Mobile applications chapter 6
Mobile applications chapter 6
 
9781305078444 ppt ch10
9781305078444 ppt ch109781305078444 ppt ch10
9781305078444 ppt ch10
 
Geoloaction
GeoloactionGeoloaction
Geoloaction
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
 
GWT training session 3
GWT training session 3GWT training session 3
GWT training session 3
 
Windows phone 7 series
Windows phone 7 seriesWindows phone 7 series
Windows phone 7 series
 
Core Location in iOS
Core Location in iOSCore Location in iOS
Core Location in iOS
 

Mehr von Suman Garai

20230513-reconFTW-CyberSapiens.pdf
20230513-reconFTW-CyberSapiens.pdf20230513-reconFTW-CyberSapiens.pdf
20230513-reconFTW-CyberSapiens.pdfSuman Garai
 
20230324-Exploring the Landscape of Password Managers for Individual Users a...
20230324-Exploring the Landscape of Password Managers for  Individual Users a...20230324-Exploring the Landscape of Password Managers for  Individual Users a...
20230324-Exploring the Landscape of Password Managers for Individual Users a...Suman Garai
 
20230105-TestCases&Oracle-MobileTesting.pdf
20230105-TestCases&Oracle-MobileTesting.pdf20230105-TestCases&Oracle-MobileTesting.pdf
20230105-TestCases&Oracle-MobileTesting.pdfSuman Garai
 
20221003-DigitalForensicTools-DigitalForensicInvestigation.pdf
20221003-DigitalForensicTools-DigitalForensicInvestigation.pdf20221003-DigitalForensicTools-DigitalForensicInvestigation.pdf
20221003-DigitalForensicTools-DigitalForensicInvestigation.pdfSuman Garai
 
20220911-ISO27000-SecurityStandards.pptx
20220911-ISO27000-SecurityStandards.pptx20220911-ISO27000-SecurityStandards.pptx
20220911-ISO27000-SecurityStandards.pptxSuman Garai
 
20220819-Ecosystem-EnviornmentalScience.pptx
20220819-Ecosystem-EnviornmentalScience.pptx20220819-Ecosystem-EnviornmentalScience.pptx
20220819-Ecosystem-EnviornmentalScience.pptxSuman Garai
 
20220728-iOSAppDev-MobileAppDev.pptx
20220728-iOSAppDev-MobileAppDev.pptx20220728-iOSAppDev-MobileAppDev.pptx
20220728-iOSAppDev-MobileAppDev.pptxSuman Garai
 
20210906-Nessus-FundamentalInfoSec.ppsx
20210906-Nessus-FundamentalInfoSec.ppsx20210906-Nessus-FundamentalInfoSec.ppsx
20210906-Nessus-FundamentalInfoSec.ppsxSuman Garai
 
20210727-Technoprenuership-EntreprenuershipDev.ppsx
20210727-Technoprenuership-EntreprenuershipDev.ppsx20210727-Technoprenuership-EntreprenuershipDev.ppsx
20210727-Technoprenuership-EntreprenuershipDev.ppsxSuman Garai
 
20210717-AntiBotnets-FundamentalInfoSec.pptx
20210717-AntiBotnets-FundamentalInfoSec.pptx20210717-AntiBotnets-FundamentalInfoSec.pptx
20210717-AntiBotnets-FundamentalInfoSec.pptxSuman Garai
 
20210417-cppRelevancy-DataStructures.pptx
20210417-cppRelevancy-DataStructures.pptx20210417-cppRelevancy-DataStructures.pptx
20210417-cppRelevancy-DataStructures.pptxSuman Garai
 

Mehr von Suman Garai (11)

20230513-reconFTW-CyberSapiens.pdf
20230513-reconFTW-CyberSapiens.pdf20230513-reconFTW-CyberSapiens.pdf
20230513-reconFTW-CyberSapiens.pdf
 
20230324-Exploring the Landscape of Password Managers for Individual Users a...
20230324-Exploring the Landscape of Password Managers for  Individual Users a...20230324-Exploring the Landscape of Password Managers for  Individual Users a...
20230324-Exploring the Landscape of Password Managers for Individual Users a...
 
20230105-TestCases&Oracle-MobileTesting.pdf
20230105-TestCases&Oracle-MobileTesting.pdf20230105-TestCases&Oracle-MobileTesting.pdf
20230105-TestCases&Oracle-MobileTesting.pdf
 
20221003-DigitalForensicTools-DigitalForensicInvestigation.pdf
20221003-DigitalForensicTools-DigitalForensicInvestigation.pdf20221003-DigitalForensicTools-DigitalForensicInvestigation.pdf
20221003-DigitalForensicTools-DigitalForensicInvestigation.pdf
 
20220911-ISO27000-SecurityStandards.pptx
20220911-ISO27000-SecurityStandards.pptx20220911-ISO27000-SecurityStandards.pptx
20220911-ISO27000-SecurityStandards.pptx
 
20220819-Ecosystem-EnviornmentalScience.pptx
20220819-Ecosystem-EnviornmentalScience.pptx20220819-Ecosystem-EnviornmentalScience.pptx
20220819-Ecosystem-EnviornmentalScience.pptx
 
20220728-iOSAppDev-MobileAppDev.pptx
20220728-iOSAppDev-MobileAppDev.pptx20220728-iOSAppDev-MobileAppDev.pptx
20220728-iOSAppDev-MobileAppDev.pptx
 
20210906-Nessus-FundamentalInfoSec.ppsx
20210906-Nessus-FundamentalInfoSec.ppsx20210906-Nessus-FundamentalInfoSec.ppsx
20210906-Nessus-FundamentalInfoSec.ppsx
 
20210727-Technoprenuership-EntreprenuershipDev.ppsx
20210727-Technoprenuership-EntreprenuershipDev.ppsx20210727-Technoprenuership-EntreprenuershipDev.ppsx
20210727-Technoprenuership-EntreprenuershipDev.ppsx
 
20210717-AntiBotnets-FundamentalInfoSec.pptx
20210717-AntiBotnets-FundamentalInfoSec.pptx20210717-AntiBotnets-FundamentalInfoSec.pptx
20210717-AntiBotnets-FundamentalInfoSec.pptx
 
20210417-cppRelevancy-DataStructures.pptx
20210417-cppRelevancy-DataStructures.pptx20210417-cppRelevancy-DataStructures.pptx
20210417-cppRelevancy-DataStructures.pptx
 

Kürzlich hochgeladen

一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样
一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样
一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样Fi
 
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0APNIC
 
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样AS
 
Lowongan Kerja LC Yogyakarta Terbaru 085746015303
Lowongan Kerja LC Yogyakarta Terbaru 085746015303Lowongan Kerja LC Yogyakarta Terbaru 085746015303
Lowongan Kerja LC Yogyakarta Terbaru 085746015303Dewi Agency
 
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)Obat Cytotec
 
一比一原版罗切斯特大学毕业证如何办理
一比一原版罗切斯特大学毕业证如何办理一比一原版罗切斯特大学毕业证如何办理
一比一原版罗切斯特大学毕业证如何办理F
 
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...ZurliaSoop
 
一比一原版美国北卡罗莱纳大学毕业证如何办理
一比一原版美国北卡罗莱纳大学毕业证如何办理一比一原版美国北卡罗莱纳大学毕业证如何办理
一比一原版美国北卡罗莱纳大学毕业证如何办理A
 
一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证学位证书
一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证学位证书一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证学位证书
一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证学位证书AS
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样ayvbos
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理F
 
原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样A
 
Dan Quinn Commanders Feather Dad Hat Hoodie
Dan Quinn Commanders Feather Dad Hat HoodieDan Quinn Commanders Feather Dad Hat Hoodie
Dan Quinn Commanders Feather Dad Hat Hoodierahman018755
 
APNIC Updates presented by Paul Wilson at CaribNOG 27
APNIC Updates presented by Paul Wilson at  CaribNOG 27APNIC Updates presented by Paul Wilson at  CaribNOG 27
APNIC Updates presented by Paul Wilson at CaribNOG 27APNIC
 
一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理AS
 
一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理SS
 
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样ayvbos
 
TOP 100 Vulnerabilities Step-by-Step Guide Handbook
TOP 100 Vulnerabilities Step-by-Step Guide HandbookTOP 100 Vulnerabilities Step-by-Step Guide Handbook
TOP 100 Vulnerabilities Step-by-Step Guide HandbookVarun Mithran
 
Loker Pemandu Lagu LC Semarang 085746015303
Loker Pemandu Lagu LC Semarang 085746015303Loker Pemandu Lagu LC Semarang 085746015303
Loker Pemandu Lagu LC Semarang 085746015303Dewi Agency
 
Abortion Pills In Jeddah+966572737505 & Get cytotec Jeddah
Abortion Pills In Jeddah+966572737505 & Get cytotec JeddahAbortion Pills In Jeddah+966572737505 & Get cytotec Jeddah
Abortion Pills In Jeddah+966572737505 & Get cytotec Jeddahmarufhussain782445
 

Kürzlich hochgeladen (20)

一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样
一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样
一比一原版(Soton毕业证书)南安普顿大学毕业证原件一模一样
 
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
 
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
 
Lowongan Kerja LC Yogyakarta Terbaru 085746015303
Lowongan Kerja LC Yogyakarta Terbaru 085746015303Lowongan Kerja LC Yogyakarta Terbaru 085746015303
Lowongan Kerja LC Yogyakarta Terbaru 085746015303
 
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)
@OBAT ABORSI 3 BULAN@ OBAT PENGGUGUR KANDUNGAN 3 BULAN (087776558899)
 
一比一原版罗切斯特大学毕业证如何办理
一比一原版罗切斯特大学毕业证如何办理一比一原版罗切斯特大学毕业证如何办理
一比一原版罗切斯特大学毕业证如何办理
 
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...
Jual obat aborsi Bekasi ( 085657271886 ) Cytote pil telat bulan penggugur kan...
 
一比一原版美国北卡罗莱纳大学毕业证如何办理
一比一原版美国北卡罗莱纳大学毕业证如何办理一比一原版美国北卡罗莱纳大学毕业证如何办理
一比一原版美国北卡罗莱纳大学毕业证如何办理
 
一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证学位证书
一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证学位证书一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证学位证书
一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证学位证书
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样原版定制美国加州大学河滨分校毕业证原件一模一样
原版定制美国加州大学河滨分校毕业证原件一模一样
 
Dan Quinn Commanders Feather Dad Hat Hoodie
Dan Quinn Commanders Feather Dad Hat HoodieDan Quinn Commanders Feather Dad Hat Hoodie
Dan Quinn Commanders Feather Dad Hat Hoodie
 
APNIC Updates presented by Paul Wilson at CaribNOG 27
APNIC Updates presented by Paul Wilson at  CaribNOG 27APNIC Updates presented by Paul Wilson at  CaribNOG 27
APNIC Updates presented by Paul Wilson at CaribNOG 27
 
一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理
 
一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理
 
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样
 
TOP 100 Vulnerabilities Step-by-Step Guide Handbook
TOP 100 Vulnerabilities Step-by-Step Guide HandbookTOP 100 Vulnerabilities Step-by-Step Guide Handbook
TOP 100 Vulnerabilities Step-by-Step Guide Handbook
 
Loker Pemandu Lagu LC Semarang 085746015303
Loker Pemandu Lagu LC Semarang 085746015303Loker Pemandu Lagu LC Semarang 085746015303
Loker Pemandu Lagu LC Semarang 085746015303
 
Abortion Pills In Jeddah+966572737505 & Get cytotec Jeddah
Abortion Pills In Jeddah+966572737505 & Get cytotec JeddahAbortion Pills In Jeddah+966572737505 & Get cytotec Jeddah
Abortion Pills In Jeddah+966572737505 & Get cytotec Jeddah
 

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();