Это видео недоступно.
Сожалеем об этом.

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

Комментарии • 30

  • @arjumandtalat
    @arjumandtalat Месяц назад

    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

  • @tazimtazvi3645
    @tazimtazvi3645 9 месяцев назад +1

    how can i take that latitude and longitude in a input field/form data to store in the data base? can you help?

  • @alanm.c.4218
    @alanm.c.4218 5 месяцев назад

    this method also work connecting to that application via phone? i mean it will ask you in your phone to allow your location?

  • @AbhishekSharma-fg1ho
    @AbhishekSharma-fg1ho 10 месяцев назад

    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

  • @dahomtech1372
    @dahomtech1372 Год назад

    Sir plz whay when open my website in android can't take theocation but when open my website by pc take location success

  • @somnathruidas648
    @somnathruidas648 17 дней назад

    Name of the extension.

  • @YoungestInCharge524
    @YoungestInCharge524 Год назад +4

    bro blurred his lat and long😂😂 are you wanted?

    • @Koded
      @Koded  Год назад +1

      Yeah. Don't call FBI

  • @krishnadhoot4141
    @krishnadhoot4141 Год назад +2

    can u provide the source code?

  • @karismapribadi
    @karismapribadi Год назад

    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?

    • @karismapribadi
      @karismapribadi Год назад

      It's worked if I run it via localhost, error while I tried this code online

  • @yashparab1304
    @yashparab1304 Год назад +1

    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?

    • @Koded
      @Koded  Год назад

      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

    • @dahomtech1372
      @dahomtech1372 Год назад

      @@Koded Sir plz whay when open my website in android can't take theocation but when open my website by pc take location success

  • @c.l5378
    @c.l5378 Год назад +1

    Is this work in Mobile phone

    • @Koded
      @Koded  Год назад

      of course, it will

  • @yashvantsinhchavda3711
    @yashvantsinhchavda3711 Год назад +1

    👍

  • @gameboyv1790
    @gameboyv1790 Год назад

    can you make it so you still get the location if they decline

    • @Koded
      @Koded  Год назад

      You can use ip address to get the location

    • @gameboyv1790
      @gameboyv1790 Год назад

      @@Koded pls help me

    • @Koded
      @Koded  Год назад

      I have shown two different ways in the video. You can try another if one doesn't work 🙂

  • @killerpop1017
    @killerpop1017 Год назад

    what app are you using?

    • @Koded
      @Koded  Год назад

      I am using Firefox and VS code.

  • @amanshetty522
    @amanshetty522 Год назад

    where can i get the source code bro

    • @mixrapmusic8118
      @mixrapmusic8118 Год назад

      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
      ```