Skip to content
Advertisement

how can I get the geolocation in html using JavaScript

I am looking for a way to get the geolocation and then convert the latitude and longitude to the closet city.

JavaScript

This is what iv got to get the latitude and longitude but am not sure how to find the closet city using them.

Advertisement

Answer

You should use an API for geolocation, I suggest ipdata for example. It’s easy to use, just put this function in your code:

JavaScript

PS: replace ${apiKey} with your ipdata API key, you will find it in your dashboard after you create an account in ipdata.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement