Это видео недоступно.
Сожалеем об этом.
Get user location with javascript || Two methods (with/without permission)
HTML-код
- Опубликовано: 14 авг 2024
- Get the user's location by geolocation API and IP address with the help of JavaScript.
You can get the user's location with or without asking for permission to use their geolocation. I have shared two methods in this video:
1. Using Geolocation API - WIth permission - 100% accurate
2, Using IP address - without permission - Not so accurate.
Timestamp:
00:00 - Preview
00:23 - Using Geolocation API
13:58 - Using IP address
17:02 - Get the city/country from latitude and longitude
17:27 - Outro
What Is the Geolocation API?
The JavaScript Geolocation API provides access to geographical location data associated with a user's device. This can be determined using GPS, WIFI, IP Geolocation and so on.
To protect the user's privacy, it requests permission to locate the device. If the user grants permission, you will gain access to location data such as latitude, longitude, altitude, and speed. You'll also get the accuracy of the acquired location data and the approximate time when the position was acquired.
Here are a few uses for geolocation:
- Show user's position on a map
- Get up-to-date local information
- Show local Points-of-interest (POI) near the user
- Enable Turn-by-turn navigation (GPS)
- Track a fleet or delivery vehicle
- Tag photographs with a location
You can access the Geolocation API by calling the navigator.geolocation object. It grants the app access to the device's location.
getCurrentPosition: Returns the current location of the device.
watchPosition: A handler function that is automatically invoked when the device's location changes.
There are three possible arguments with these methods:
A success callback (required)
An error callback (optional)
An options object (optional)
How to Get User Location with getCurrentPosition()
You can use the getCurrentPosition method to get the user's current location. It sends an asynchronous request to the browser, asking for consent to share their location
WORTH CHECKING:-
Hosting websites for free(playlist):
• Free Web Hosting
Making Facebook Clone using HTML & CSS:
• How to create a websit...
Send EMAIL without backend (using HTML):
• How to send email usin...
Top 5 online CODE editors:
• Top 5 Free Online Code...
AROUND THE WEB:
GitHub: @aashishpanthi
www.github.com...
Instagram: @aashishpanthi11
/ aashishpanthi11
Dev.to: @aashishpanthi
dev.to/aashish...
Do not click this 🥴: bit.ly/352wEsG
-------------------------------------------------------------------------------------
Hey there lovely people, this channel is about WEB DEVELOPMENT && PROGRAMMING. Here, I upload videos once in every uncertain time 😜. Mainly, videos are related to tutorials and informative videos.
#code #location #javascript
I tried this on my pc and it showed the details there but when i used my phone to access the website and click the button and then i checked in the console of my pc, it didnt show anything and i couldnt see the user’s (my phone’s) lat long and stuff i can only see when i use my pc
how can i take that latitude and longitude in a input field/form data to store in the data base? can you help?
this method also work connecting to that application via phone? i mean it will ask you in your phone to allow your location?
in my case its not asking location and i am facing error which is can not access location and site is also not secure what i do
Sir plz whay when open my website in android can't take theocation but when open my website by pc take location success
Name of the extension.
bro blurred his lat and long😂😂 are you wanted?
Yeah. Don't call FBI
can u provide the source code?
Hi bro, I want just to run script.js only, not with IP, but after I upload it on hosting, permission always denied, I tried in different device but the error result still same, do you have suggestion?
It's worked if I run it via localhost, error while I tried this code online
If a user already or previously agrees to share his location or means we have its permission now we directly access its location,when the website is getting loaded , how can we implement that in javascript?
yep, that works with the code in the video. If the user agrees, it is saved in the browser and the if condition in our code checks for the same
@@Koded Sir plz whay when open my website in android can't take theocation but when open my website by pc take location success
Is this work in Mobile phone
of course, it will
👍
👍
can you make it so you still get the location if they decline
You can use ip address to get the location
@@Koded pls help me
I have shown two different ways in the video. You can try another if one doesn't work 🙂
what app are you using?
I am using Firefox and VS code.
where can i get the source code bro
Here's an example of how to use the Geolocation API in HTML:
```html
Geolocation Example
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
alert("Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert("Latitude: " + latitude + "
Longitude: " + longitude);
}
Get Location
```