Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5928601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:18:39+00:00 2026-05-22T14:18:39+00:00

i get user location via navigator.geolocation. What i need is using user geolocation in

  • 0

i get user location via navigator.geolocation. What i need is using user geolocation in my controller for sorting by distance. How to get navigator.geolocation from the controller? Is there some global storage for this kind of javascript object for each user?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:18:40+00:00Added an answer on May 22, 2026 at 2:18 pm

    You should send geolocation from javascript to rails via POST/COOKIE.

    jQuery

    $(function(){ 
      navigator.geolocation.getCurrentPosition(function(pos){
        $.post('/set_geolocation',{latitude: pos.coords.latitude, longitude: pos.coords.longitude}) 
      });      
    });
    

    Rails

    # routes.rb
    ...
    post '/set_geolocation' => 'users#set_geolocation'
    ... 
    
    
    # users_controller.rb
    class UsersController < ApplicationController
      def set_geolocation
        session[:location] = {:latitude=> params[:latitude], :longitude=> params[:longitude]}
      end
    end
    

    Or

    jQuery

    $(function(){ 
      navigator.geolocation.getCurrentPosition(function(pos){
        document.cookie = document.cookie + '; latitude=pos.coords.latitude; longitude=pos.coords.longitude'
      });      
    });
    

    Rails

    # somewhere in controllers
    …cookie[:latitude]…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery to get visitor's location via their IP address. There's a
I'm using the Google API to get a user's location on this site .
I would like to get the address string of the current user location. Is
Which permission needs my application to get access to the location of the user
I'm trying to get user GUID from Active Directory. My code: DirectoryEntry entry =
How to get user roles from Membership provider? Suppose I have a username and
is there a way to get user input like an inputbox in c#? i
I've got some nested objects in rails. User -> has_many :tasks -> has_one :location.
What i need is the lat/long of the client(via browser) Found some articles on
How can I get the location that the user has clicked on the map

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.