Rahul Dess
Rahul Dess

Reputation: 2597

Get user's location (latitude, longitude) when visited

Whenever a user enters my site, i want to get his longitude, latitude to further use in my google maps. I have tried using HTML5 geolocation script and geocoder gem.

Using Geocoder gem, my hash is empty when trying below code, why is this happening ? Is this because i am running it in localhost ? Please suggest how to get it done if any other way.

I just need latitude and longitude of my user, thats it.

location = request.location
longitude = location.data['longitude']

Upvotes: 0

Views: 103

Answers (1)

nonameg
nonameg

Reputation: 136

If you had carefully read documentation of geocoder gem you would notice that:

Note that these methods will usually return nil in your test and development environments because things like "localhost" and "0.0.0.0" are not an Internet IP addresses.

Upvotes: 0

Related Questions