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

146
Views
How do you manage geolocation on mobile device? (Server side or Client-side/ permission management)

I'am working on app that ask geolocation to render data around a place. The location is asked with the first page is loaded.

I tried 2 approachs:

Server-side with the gem 'geocoder', it works on my PC but on Iphone and android is working sometimes (maybe due to the timeout ? i set the maximum value but it don't change anything)

  def localize
    @location = lookup_ip_location
    if @location.data["loc"].nil?
        @user.latitude = 48.49
        @user.longitude = -2.7
      else
        @user.latitude = @location.data['loc'].split(',').first.to_f
        @user.longitude = @location.data['loc'].split(',').second.to_f
    end
  end

Client-side with the script 'navigator.geolocation.getCurrentPosition' , it works on PC but on mobile device, it's random and i can't pinpoint the main issue. On Iphone, sometimes, i need to unlock some privacy setting, on Android, i don't know.

<div class="container">
<input type="text" id="latitude">
<input type="text" id="longitude">
</div>

    
<script>

    let latloc = document.getElementById('latitude');
    let lonloc = document.getElementById('longitude');

    var options = {
      enableHighAccuracy: true,
      timeout: 5000,
      maximumAge: 0
    };
    
    function error(err) {
      console.warn(`ERROR(${err.code}): ${err.message}`);
    }
    
    
    function setGeoCookie(position) {
      var cookie_val = position.coords.latitude + "|" + position.coords.longitude;
      document.cookie = "lat_lng=" + escape(cookie_val);
      latloc.value = position.coords.latitude;
      lonloc.value = position.coords.longitude;
    }
    
    function getGeoLocation() {
      navigator.geolocation.getCurrentPosition(setGeoCookie, error, options);
    }
    
    getGeoLocation();
    
    </script>

How do you manage location (and permission if needed) on a Rails app ?

Thanks

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!