Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Google maps gem

I am wondering what is the best gem to use in order to make a web application using google maps. where is the best place to learn about this and how to do it. I want my application to be similar to this wp theme http://www.elegantthemes.com/demo/?theme=Explorable any ideas? Thanks everyone!

3 Answers

If you can get through it, look at the build an interactive website island. You'll be able to take from that, if you ca, what you need to know to make that theme.

Or just buy the theme? The code is already written.

I spent a long time looking into this when I was building a mapping widget for a client. gmaps4rails was the best that I could find. It will take a bit to configure to your needs, and sometimes the documentation can be a bit thin in some instances, so it may take a bit of trial and error to figure it all out. In my particular instance I was trying to do something kind of complex. I was detecting the user IP Address, then geocoding it, then sending those lat long quadrates to the mapping view to display the applications mapping data on the users detected location without having to perform a HTML5 geolocation prompt. So that was probably a somewhat difficult thing to do anyway, and it took a week or two of work to get it functioning properly with gmaps4rails.

Lee Hughes
Lee Hughes
8,380 Points

Hey Riley Hilliard I'm currently researching this. I need to provide information according to a users IP address, ideally more accurate than city location, not sure if this is possible though. I know I can pay for a database from MaxMind which will have more accurate results, still researching at the moment.

But I was wondering if you still used gmaps4rails or if you had found a better service for Ruby, any help to get me on the right track is much appreciated.

Cheers

I never found a good free alternative that was accurate, but maybe try some of these?

Lee Hughes
Lee Hughes
8,380 Points

Cheers bud, will research :)

This seems to work pretty well for Geocoding an IP address: http://freegeoip.net/{format}/{ip_or_hostname} For the format you can specify csv, xml or json. I prefer json, but the formats up to you. All you need to do then is write some code to detect the IP address, then pass it into the API call to freegeoip EX: $detected_IP_addrss = however_you_want_to_detect_their_ip_address; $locationData = "http://freegeoip.net/json/".$detected_IP_addrss; Then just parse the return data and use whatever you want from it. freegeoip.net returns a lot of useful info like city, state, country, region, zip, lat, long. You could pass one of those into Google maps and have it drop a pin, center the map, or whatever.

Hmmm, the code formatter didnt work... $detected_IP_addrss = however_you_want_to_detect_their_ip_address; $locationData = "http://freegeoip.net/json/".$detected_IP_addrss;

Elizabeth Fawkes ^^ Just a heads up, there needs to be a way to be able to edit reply messages . . . ^^

Hi Riley Hilliard ! Great idea. :) You should already be able to do that, but let's see if the Dev Team has a similar feature in the works /cc Tommy Morgan .

Lee Hughes
Lee Hughes
8,380 Points

Cheers Riley Hilliard, I've been looking at https://www.maxmind.com/en/home which so far has the most accurate data I've found and is constantly updated. I'll check out the freegeoip link and consider the pros and cons of each :)

Why use a gem? the api is simple enough to use, not everything in rails has to use a gem :)