Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Ask for user permission Location on Smartphone

I am using Geolocation API to detect the location of the user. I want now to get the location of the user on the smartphone. I have read the thread on I set geolocation permission in the manifest, but every page still asks to share location. But it is 8 years old. Is it possible to get the location of the user on smartphone? Should I write the Manifest for every single browser?

This is my code for this:

 <script>
const geoinfo = document.getElementById("geoinfo"); // not necessary thanks to IE quirk but good practice
 
navigator.geolocation.getCurrentPosition = function(success, error, options) { ... };
 
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function (position) {
        const { latitude, longitude, altitude } = position.coords;
        //geoinfo.innerHTML = `Breitengrad: ${latitude}, Längengrad: ${longitude}`;
        if (altitude) geoinfo.innerHTML += `, Höhe über Meeresspiegel: ${altitude}`;
        // send to server
        sendData(latitude, longitude);
    });
} else {
    geoinfo.innerHTML = 'Dieser Browser unterstützt die Abfrage der Geolocation nicht.';
}
 
async function sendData(lat, long) {
    const response = await fetch(`?lat=${lat}&long=${long}`); // send data to this script, regardless of filename
    if (response.ok) {
        const text = await response.text();
        if (text == "received") alert("Geodaten erfolgreich zum Server gesendet.");
    }
}   
    </script>

It is only working on Desktop PC´s....

This code which I found from the doc does not work?

 var options = {
      enableHighAccuracy: true,
      timeout: 5000,
      maximumAge: 0
    };

    function success(pos) {
      var crd = pos.coords;

      console.log('Your current position is:');
      console.log(`Latitude : ${crd.latitude}`);
      console.log(`Longitude: ${crd.longitude}`);
      console.log(`More or less ${crd.accuracy} meters.`);
    };

    function error(err) {
      console.warn(`ERROR(${err.code}): ${err.message}`);
    };

    navigator.geolocation.getCurrentPosition(success, error, options);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!