SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
HTML 5 Geolocation API
Muhammad Ehtisham Siddiqui
Aptech Computer Education
What is Geolocation
 The HTML Geolocation API is used to locate a user's position.
 he HTML Geolocation API is used to get the geographical position of a user.
 Geolocation is most accurate for devices with GPS, like iPhone.
Browsers Support
API Chrome Internet Explorer Firefox Safari Opera
Geolocation 5.0 - 49.0 (http)
50.0 (https)
9.0 3.5 5.0 16.0
How to use API
 Check if Geolocation is supported
 If supported, run the getCurrentPosition()
method. If not, display a message to the user
 If the getCurrentPosition() method is
successful, it returns a coordinates object to
the function specified in the parameter
(showPosition)
 The showPosition() function outputs the
Latitude and Longitude
 if (navigator.geolocation)
 if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition
(showPosition); }
 function showPosition(position) {
x.innerHTML = "Latitude: " +
position.coords.latitude +
"<br>Longitude: " +
position.coords.longitude;
}
Steps
Check if Geolocation
is supported
If supported, run the
getCurrentPosition()
method. If not,
display a message to
the user
If the
getCurrentPosition()
method is
successful, it returns
a coordinates object
to the function
specified in the
parameter
(showPosition)
The showPosition()
function outputs the
Latitude and
Longitude
Example Code
Finding Longitude & Latitude
<!DOCTYPE html><html><body>
<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">Try It</button><p id="demo"></p><script>var x = document.getElementById("demo");
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;}
</script></body> </html>
Displaying the result in MAP
<!DOCTYPE html><html><body><p id="demo">Click the button to get your position.</p><button onclick="getLocation()">Try It</button><div
id="mapholder"></div><script>
var x = document.getElementById("demo");
function getLocation() {
if
(navigator.geolocation) {navigator.geolocation.getCurrentPosition(showPosition, showError);}
else {
x.innerHTML = "Geolocation is not supported by this browser."; }}function showPosition(position) {var latlon = position.coords.latitude + "," +
position.coords.longitude;
var img_url = "https://maps.googleapis.com/maps/api/staticmap?center="
+latlon+"&zoom=14&size=400x300&key=AIzaSyBu-916DdpKAjTmJNIgngS6HL_kDIKU0aU";
document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>";}
}</script></body></html>
OutPut
Video
Video
Html 5 geolocation api

More Related Content

PPTX
PDF
[Android] Services and Broadcast Receivers
PDF
Android ui layout
PDF
Android Fragment
PPTX
PPTX
Applets in java
PPT
Introduction to Android Fragments
PDF
Learning jQuery in 30 minutes
[Android] Services and Broadcast Receivers
Android ui layout
Android Fragment
Applets in java
Introduction to Android Fragments
Learning jQuery in 30 minutes

What's hot (20)

PPTX
Java script
PPTX
Android Navigation Component
PPSX
Javascript variables and datatypes
PPTX
Form Handling using PHP
PDF
Php introduction
PPTX
Lab #2: Introduction to Javascript
PPTX
Client side scripting using Javascript
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
PPTX
Dom(document object model)
PPTX
Introduction to DOM
PPTX
Javascript event handler
PPTX
Reactjs
PPTX
jQuery PPT
PDF
CSS Positioning Elements.pdf
PPTX
JAVA ENVIRONMENT
PPTX
Flask – Python
PDF
JavaScript - Chapter 12 - Document Object Model
PPTX
Telephony API
Java script
Android Navigation Component
Javascript variables and datatypes
Form Handling using PHP
Php introduction
Lab #2: Introduction to Javascript
Client side scripting using Javascript
JavaScript - Chapter 13 - Browser Object Model(BOM)
Dom(document object model)
Introduction to DOM
Javascript event handler
Reactjs
jQuery PPT
CSS Positioning Elements.pdf
JAVA ENVIRONMENT
Flask – Python
JavaScript - Chapter 12 - Document Object Model
Telephony API
Ad

Similar to Html 5 geolocation api (20)

PPTX
PPTX
20220816-GeolocationAPI-AdvancedWebDevelopment.pptx
PPTX
Windows Phone 8 - 15 Location and Maps
PDF
Corso WebApp iOS - Lezione 07: iOS WebApp Anatomy
PDF
How to use geolocation in react native apps
PPTX
U3-03-Google Location Based Services.pptx
PDF
Android App Development 04 : Location API
PDF
Google Maps Api
PDF
mobl
PDF
International Journal of Engineering Research and Development
PPTX
097 smart devices-con_las_aplicaciones_de_gestión
PDF
Bibliotecas Google para iOS: Fanboy é a sua vó
PPTX
Geoloaction
PDF
3D Touch: Preparando sua app para o futuro do iOS
PDF
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Jforum S...
PDF
AI: Integrate Search Function into Your App Using Bing Search API.
ODP
Android Location-based應用開發分享
PPT
Google Geo APIs Overview
PPT
Mobile webapplication development
PDF
Reaching out from ADF Mobile (ODTUG KScope 2014)
20220816-GeolocationAPI-AdvancedWebDevelopment.pptx
Windows Phone 8 - 15 Location and Maps
Corso WebApp iOS - Lezione 07: iOS WebApp Anatomy
How to use geolocation in react native apps
U3-03-Google Location Based Services.pptx
Android App Development 04 : Location API
Google Maps Api
mobl
International Journal of Engineering Research and Development
097 smart devices-con_las_aplicaciones_de_gestión
Bibliotecas Google para iOS: Fanboy é a sua vó
Geoloaction
3D Touch: Preparando sua app para o futuro do iOS
Microservices for the Masses with Spring Boot, JHipster, and OAuth - Jforum S...
AI: Integrate Search Function into Your App Using Bing Search API.
Android Location-based應用開發分享
Google Geo APIs Overview
Mobile webapplication development
Reaching out from ADF Mobile (ODTUG KScope 2014)
Ad

More from Muhammad Ehtisham Siddiqui (20)

PPTX
C programming Tutorial Session 4
PPTX
C programming Tutorial Session 4
PPTX
C programming Tutorial Session 3
PPTX
C programming Tutorial Session 2
PPTX
C programming Tutorial Session 1
PPTX
HTML5 Web storage
PPTX
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
PPTX
JavaScript Session 2
PPTX
JavaScript Session 3
PPTX
Javascript session 1
PPTX
Html audio video
PPTX
Buiding Next Generation Websites Session 8 by Muhammad Ehtisham Siddiqui
PPTX
Building Next Generation Websites Session 7 by Muhammad Ehtisham Siddiqui
PPTX
Building Next Generation Websites Session 6 by Muhammad Ehtisham Siddiqui
PPTX
Building Next Generation Websites by Muhammad Ehtisham Siddiqui
PPTX
Building Next Generation Websites Session6
PPTX
Building Next Generation Websites Session5
PPTX
Building Next Generation Websites Session4
PPTX
Office session14
C programming Tutorial Session 4
C programming Tutorial Session 4
C programming Tutorial Session 3
C programming Tutorial Session 2
C programming Tutorial Session 1
HTML5 Web storage
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
JavaScript Session 2
JavaScript Session 3
Javascript session 1
Html audio video
Buiding Next Generation Websites Session 8 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session 7 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session 6 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session6
Building Next Generation Websites Session5
Building Next Generation Websites Session4
Office session14

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
master seminar digital applications in india
PDF
RMMM.pdf make it easy to upload and study
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Sports Quiz easy sports quiz sports quiz
Insiders guide to clinical Medicine.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Renaissance Architecture: A Journey from Faith to Humanism
Final Presentation General Medicine 03-08-2024.pptx
Anesthesia in Laparoscopic Surgery in India
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Pre independence Education in Inndia.pdf
Microbial disease of the cardiovascular and lymphatic systems
Microbial diseases, their pathogenesis and prophylaxis
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
master seminar digital applications in india
RMMM.pdf make it easy to upload and study
human mycosis Human fungal infections are called human mycosis..pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Computing-Curriculum for Schools in Ghana
TR - Agricultural Crops Production NC III.pdf
Sports Quiz easy sports quiz sports quiz

Html 5 geolocation api

  • 1. HTML 5 Geolocation API Muhammad Ehtisham Siddiqui Aptech Computer Education
  • 2. What is Geolocation  The HTML Geolocation API is used to locate a user's position.  he HTML Geolocation API is used to get the geographical position of a user.  Geolocation is most accurate for devices with GPS, like iPhone.
  • 3. Browsers Support API Chrome Internet Explorer Firefox Safari Opera Geolocation 5.0 - 49.0 (http) 50.0 (https) 9.0 3.5 5.0 16.0
  • 4. How to use API  Check if Geolocation is supported  If supported, run the getCurrentPosition() method. If not, display a message to the user  If the getCurrentPosition() method is successful, it returns a coordinates object to the function specified in the parameter (showPosition)  The showPosition() function outputs the Latitude and Longitude  if (navigator.geolocation)  if (navigator.geolocation) { navigator.geolocation.getCurrentPosition (showPosition); }  function showPosition(position) { x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude; }
  • 5. Steps Check if Geolocation is supported If supported, run the getCurrentPosition() method. If not, display a message to the user If the getCurrentPosition() method is successful, it returns a coordinates object to the function specified in the parameter (showPosition) The showPosition() function outputs the Latitude and Longitude
  • 7. Finding Longitude & Latitude <!DOCTYPE html><html><body> <p>Click the button to get your coordinates.</p> <button onclick="getLocation()">Try It</button><p id="demo"></p><script>var x = document.getElementById("demo"); 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;} </script></body> </html>
  • 8. Displaying the result in MAP <!DOCTYPE html><html><body><p id="demo">Click the button to get your position.</p><button onclick="getLocation()">Try It</button><div id="mapholder"></div><script> var x = document.getElementById("demo"); function getLocation() { if (navigator.geolocation) {navigator.geolocation.getCurrentPosition(showPosition, showError);} else { x.innerHTML = "Geolocation is not supported by this browser."; }}function showPosition(position) {var latlon = position.coords.latitude + "," + position.coords.longitude; var img_url = "https://maps.googleapis.com/maps/api/staticmap?center=" +latlon+"&zoom=14&size=400x300&key=AIzaSyBu-916DdpKAjTmJNIgngS6HL_kDIKU0aU"; document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>";} }</script></body></html>
  • 10. Video
  • 11. Video