Skip to content

baralmanish/getCurrentAddress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Get Current address using Javascript Code

We can use browser nagivigator to get current location. And using that location's latitude and longitude we invoke the openstreetmap api to get current address.

navigator.geolocation.getCurrentPosition((position) => {
  const { latitude, longitude } = position.coords;
  const url = `https://nominatim.openstreetmap.org/reverse?format=json&lat=${latitude}&lon=${longitude}`;
  fetch(url)
    .then((res) => res.json())
    .then((data) => {
      console.log(data.display_name);
      console.table(data.address);
    })
    .catch(() => console.error("Error on fetching data."));
});

DEMO

Click here to see the demo

https://my-address.netlify.app

About

Code to get current address using javascript code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages