mlzboy
mlzboy

Reputation: 14721

Getting user city with Rails3 + Google Maps

When people visit my web site, I want get the user's IP, then locate the city on google map and show information relevant to the visitor's city.

What gems can help me? Or give me some advice. Thanks.

Upvotes: 1

Views: 232

Answers (2)

Mischa
Mischa

Reputation: 43318

The Geocoder gem will help you. This Railscast explains how you can use Geocoder.

Upvotes: 0

Trott
Trott

Reputation: 70163

Rather than getting the user's IP, especially if you expect most of the users will be mobile/handheld users, you might be better off using JavaScript Geolocation and Google Maps Reverse Geocoding. See http://dev.w3.org/geo/api/spec-source.html and http://code.google.com/apis/maps/documentation/javascript/services.html#ReverseGeocoding.

On the other hand, if you really do want to use the user's IP, check out Center Google Map Based on geocoded IP.

There may be Gems that wrap these services up for you, but if not, they're fairly straightforward.

Upvotes: 1

Related Questions