hi, i found 2 plugins that incorporate google maps into a rails application(cartographer and ym4r(misspelled)). i just came across this http://earthcode.com/blog/2006/04/rails_geocoding_and_google_map.html now i am confused. what does the 'plugins' do vs the code found at the above link? in terms of taking a basic address and creating a map?
on 21.08.2006 16:48
on 21.08.2006 20:57
koloa wrote: > hi, > i found 2 plugins that incorporate google maps into a rails > application(cartographer and ym4r(misspelled)). > > i just came across this > http://earthcode.com/blog/2006/04/rails_geocoding_and_google_map.html > > now i am confused. what does the 'plugins' do vs the code found at the > above link? in terms of taking a basic address and creating a map? If all you are trying to do is create a map from a single origin and destination address then you don't need either! You can do something like this and not have a need for an API key: ********************************************************* <td valign='bottom' nowrap align='center'> <% if @lead then %> <form action="http://maps.google.com/maps" target="_blank" method="get"> <input type="hidden" name="saddr" id="saddr" value="<%= @lead.origin_zip && @lead.origin_zip.length > 0 ? @lead.origin_zip : ( @lead.origin_city.to_s + ', ' + @lead.origin_state.to_s ) %>" /> <input type="hidden" name="daddr" value="<%= @lead.destination_zip && @lead.destination_zip.length > 0 ? @lead.destination_zip : ( @lead.destination_city.to_s + ', ' + @lead.destination_state.to_s ) %>" /> <input type="hidden" name="hl" value="en" /></p> <input type="submit" value="Show Map" /> </form> <% end %> </td> ************************************ If you need something more elaborate then I can let you know that I just integrated with ym4r last night and am quite pleased with it. Regards, Michael
on 22.08.2006 02:36
well what i would like to do is convert addresses in my database to google maps and embed them in a 'details' page about the user. what do you think is the best method to do this? it seems like all i have to do is make a call to a webservice and get the address converted to lat/long and pass that to google? thanks.
on 22.08.2006 03:06
That seems to be the best way, as google doesnt seem to provide an address to long/lat conversion ..as far as I know... for instance, if you had an array of addresses you wanted to put pins of on a map you need the long/lat data
on 22.08.2006 05:44
Clayton Cottingham wrote: > That seems to be the best way, > as google doesnt seem to provide an address to long/lat conversion > > ..as far as I know... > > for instance, if you had an array of addresses you wanted to put pins of > on > a map you need the long/lat data Google does provide a lat/long tool. You give it an address (or zip) and it will return the coords for you in an option of formats (xml, json, csv, etc...). This is part of the ym4r GEM that can be used in conjunction with the ym4r plugin or standalone. However, you do need to have a developer key UNLESS everything is coming from localhost - then you can use the key supplied by ym4r. FYI...based on some testing I have just completed, it is best to have a server process get the lat/long coordinates and store them in your database for later retrieval, if possible for your app. The call itself can be slow when you are passing in several items to geocode whereas if you are just placing pins on the map then it is very quick when you have the coords already stored. ym4r will do what you need! I downloaded it last night and have a functioning map setup with markers and polylines. The plugin is extremely useful and I highly recommend it. Michael
on 22.08.2006 06:35
Ym4r is good stuff, I'm using it in a project right now. Geocoding through google is limited though to one request every couple of seconds, which in our case wasn't good enough. I actually grabbed the raw census data (TIGER), then used the geocoder.us perl code to compile our own database. Then I made up a quick webservice that queries our database first then google if it can't be found, and caches any of the google replies for future lookup.
on 22.08.2006 06:39
By the way, does anyone know of a free service that will let you host large files for download? Say 800 mb? I'd be happy to share the TIGER database I compiled using the geocoder.us code, but I can't afford to make it available off our servers. Then maybe someone would have a reason to convert the perl module to ruby. I've been to lazy:)
on 22.08.2006 13:43
Hello Micheal, Thanks for the reply. about the api google map key, under what url do i register if i want my view "show_google_maps" to display a google map? localhost:3000/start/show_google_maps ive tried about ever variation of the above and I still kept getting the "key is invalid..." in the link i posted and said just to register under localhost:3000, but it didnt work. also, i plan on doing the geocoding lookup everytime a new address is submitted into our database. is this what you mean by having a server process? Michael Modica wrote: > Clayton Cottingham wrote: >> That seems to be the best way, >> as google doesnt seem to provide an address to long/lat conversion >> >> ..as far as I know... >> >> for instance, if you had an array of addresses you wanted to put pins of >> on >> a map you need the long/lat data > > Google does provide a lat/long tool. You give it an address (or zip) > and it will return the coords for you in an option of formats (xml, > json, csv, etc...). This is part of the ym4r GEM that can be used in > conjunction with the ym4r plugin or standalone. However, you do need to > have a developer key UNLESS everything is coming from localhost - then > you can use the key supplied by ym4r. > > FYI...based on some testing I have just completed, it is best to have a > server process get the lat/long coordinates and store them in your > database for later retrieval, if possible for your app. The call itself > can be slow when you are passing in several items to geocode whereas if > you are just placing pins on the map then it is very quick when you have > the coords already stored. > > ym4r will do what you need! I downloaded it last night and have a > functioning map setup with markers and polylines. The plugin is > extremely useful and I highly recommend it. > > Michael
on 22.08.2006 17:19
koloa wrote: > Hello Micheal, Thanks for the reply. > > about the api google map key, under what url do i register if i want my > view "show_google_maps" to display a google map? > > localhost:3000/start/show_google_maps > > ive tried about ever variation of the above and I still kept getting the > "key is invalid..." in the link i posted and said just to register under > localhost:3000, but it didnt work. > > > also, i plan on doing the geocoding lookup everytime a new address is > submitted into our database. is this what you mean by having a server > process? > If you are using localhost then you should not have to do anything assuming you followed the directions/tutorial on the ym4r website. Take special note to the "<%= GMap.header(:with_vml => false) %>" setting that should be in your view/layout. I believe this is the one that sends the key to google for validation. I suggest using the tutorial that has the yahoo traffic in it. It does require the gem to be installed also (simple) but doesn't require any database changes on your part. If you follow that tutorial exact then you should quicly be able to figure out if it is something you are missing and backtrack from there. Make sure that development key is in your config directory as the tutorial indicates (the development key that comes with ym4r is good for development). Regards, Michael
on 22.08.2006 17:24
> also, i plan on doing the geocoding lookup everytime a new address is > submitted into our database. is this what you mean by having a server > process? > Yes - as a previous poster mentioned google throttles the lookup speed (or it's just slow) - I believe it is one a second or so. If you have a background task or something that can do this for you then the user doesn't suffer while waiting for the map to draw. You can certainly do it on the save of the address record and just have the user wait an additional second. My point was don't try to do this WHEN you are drawing the map with the markers if you don't have to. Imagine having 100 markers on the map - you would be waiting at least 100 seconds to get the map to display if you were geocoding at that point in time. If, however, you have those values stored then the map will load much faster. Regards, Michael
on 22.08.2006 18:06
hey Michael thanks, your advice is very well appreciated!