Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda