31 Comments
- terinjokes, on 10/12/2007, -4/+9I'm making a PHP guestmap-type thing using googlemaps, that interconnects to my e107, i am thinking about picking up ROR, so nice tutorial
- adkinsjm, on 10/12/2007, -0/+5It's as simple as bulding an aviary or an olympic-size swimming pool.
- Dietrich, on 10/12/2007, -4/+8You will not regret learning Ruby. Incredibly useful programming language.
- Razerious, on 10/12/2007, -0/+4I'm thinking about moving from PHP to Ruby/ROR as well. The syntax is very clean, and ROR seems to be an awesome framework.
- Kam3k, on 10/12/2007, -1/+5This tutorial isn't an ideal example of the right way to this kind of thing in Rails.
It's be better to make use of Rails web services client, ActionWebService::Client::XmlRpc
The a lot of the code doesn't' really belong in a controller and should be extracted into a model, (Models don't necessarily have to extend ActiveRecord.)
each_with_index is used when just 'each' would do, the index isn't needed - Tkkt, on 10/12/2007, -5/+8Duel at high noon. You bring your longitude, I'll bring the latitude.
- trovster, on 10/12/2007, -0/+3Good tutorial if you live in the USA (because off the Geocoder). Unfortunately, I do not.
- Kam3k, on 10/12/2007, -0/+3Rails has XMLRPC and SOAP clients as part of ActionWebService, examples and docs here:
http://api.rubyonrails.com/classes/ActionWebService/Client/XmlRpc.html and
http://api.rubyonrails.com/classes/ActionWebService/Client/Soap.html - Kam3k, on 10/12/2007, -0/+2The XMLRPC and SOAP clients work with any web services based on those protocols. They simply allow you to invoke remote methods like the example: posts = blog.getRecentPosts where posts is an instance of your web service client. If your API method requires parameters through the query string it must be a REST API where the URL contains all information required to process that request, unlike SOAP or XMLRPC where the URL stays the same.
- Kam3k, on 10/12/2007, -0/+2That's right, delicious uses REST. I don't know of a very 'Rails' way to use them though not having tried it. I'd be interested if anyone else does.
- atheken, on 10/12/2007, -1/+3I actually wrote a whole wrapper class for Google Maps a few months ago, including geocoding from Yahoo! API (how perverse). The Yahoo! API uses Navteq from what I can tell and tends to be much more accurate than the TIGER data - I've heard TIGER 2010 is going to be amazing, though. If you are interested: http://www.andrewtheken.com/?page=GMapsClass
- Kam3k, on 10/12/2007, -1/+3not much since it doesn't make good use of what Rails provides. For instance they could have used the google maps helper plugin: http://cartographer.rubyforge.org/
- Fantt, on 10/12/2007, -0/+2I've found lots of different ways to call web service APIs from Ruby, but I don't know what the best way or the most current method is. Does anyone have a really good resource?
- Razerious, on 10/12/2007, -1/+2No one claimed this was only possible with Ruby, but this tutorial was written with Ruby/ROR in mind, so I think it's quite natural to mention that in the headline and blurb.
- inactive, on 10/12/2007, -1/+2I can digg it! Ahahahah
- piesforyou, on 10/12/2007, -1/+2latitude is definately superior. Longitude doesn't tell you anything useful...
- Fantt, on 10/12/2007, -0/+1Ohhh... so, REST APIs like the one that delicious exposes isn't covered by either of these two classes, right? I've seen some examples of how to call REST APIs using open-uri. Is there a more Railsish way to do it? Thanks again for your answers!
- Fantt, on 10/12/2007, -0/+1Thanks Kam3k. I just looked at the link for XmlRpc and I'm a little confused. It says that one of the parameters for the new method, "api must be an ActionWebService::API::Base derivative." Does that mean that you can only use this to call Webservices built with RoR? If not, what goes in that parameter? Also, I'm not clear after reading the docs how I would call an API method that takes query string parameters.
Sorry for the noob questions. Any help would really be appreciated though! - Fantt, on 10/12/2007, -2/+2I've found that the amount of code that is required to do stuff like this is generally smaller in Ruby. Many people also find Ruby to be a lot more readable than other languages (php comes to mind). Of all the languages I've used in the last 10 years, Ruby is just the most fun to code in. I agree that in the end, language choice really only matters nowadays as a personal choice.
- Kam3k, on 10/12/2007, -2/+2It gets much more interesting in Rails when you're creating your own web services. For example you can set up a single controller action to handle both normal web requests and also REST service requests. Then you can have your ActiveRecord objects automatically turned into XML for the response. That's how the basecamp API works.
http://jamis.jamisbuck.org/articles/2006/03/27/web-services-rails-style - Silby, on 10/12/2007, -7/+7I love longitude
- dturanski, on 10/12/2007, -0/+0See my comment in above thread. I meant to post reply here.
- mgainor, on 10/12/2007, -1/+1What does this have to do with Ruby? It's easy to use Google Maps on your site with any language. Between Google's API and a geocoding service, anything that takes any significant thought is already done for you. The language you use is quickly becoming irrelevant.
- nymbot, on 10/12/2007, -0/+0That's probably because you live in a country that has some backwards attitude towards public data, such as maps.
http://publicgeodata.org/Home - dirtDIGGler, on 10/12/2007, -0/+0What if I want to attach my GIS database to something like this. So i can have a visual representation of all my properties. I have the Lat and Long of every property. Now, If I click on the flags it should give me the file number/location/owner etc. Is that possible? All the GIS info is MS Access. Any suggestions?
- sfac, on 10/12/2007, -0/+0That's a pretty straightforward application for Google Maps. There are lots of folks who could help you with a project like that. The language of implentation probably doesn't matter too much, just get someone who is familiar with the Google Maps API
- sfac, on 10/12/2007, -0/+0Kam3k: thanks for pointing out cartographer at rubyforge. And you're right, if you take this code forward, you will want to abstract things down to models rather than keeping everything n the controller. For learning purposes though, it's helpful to see the code in one or two files.
- dturanski, on 10/12/2007, -0/+0For REST, open-uri is it. I wrote a REST Request class to make it easier:
This example calls the Yahoo Geocoder:
require 'request'
require 'rexml/document'
request=REST::Request.new
appId,zip,url='dturanski',19312,'[Yahoo Geocode Base URL Goes Here - can't include in a comment]'
['791 Cassatt Road',
'448 Churchill Drive',
'546 Coldstream Dr',
'473 Westwind Drive'].each {|address|
# submit the request with parameters
result=request.submit(url,:appid=>appId,:zip=>zip,:street=>address)
# parse the result
doc = REXML::Document.new(result)
p "Latitude=" REXML::XPath.first( doc, '*/Result/Latitude').text " Longitude=" REXML::XPath.first( doc, '*/Result/Longitude').text
}
#===============================================
# The REST Module (request.rb)
#===============================================
require 'open-uri'
module REST
class Request
def initialize(url=nil)
if validURL(url) || url==nil
@url=url
else
raise ArgumentError, "#{url} is not a valid URL (supported protocols are http,https)"
end
end
def submit(*args)
a=args.shift
url=nil
if (a.is_a? String)
url=a
params=args.shift
else
params=a
end
url||=@url
raise ArgumentError, "argument is of type #{params.class}-must be a Hash " unless params.is_a?(Hash)
pre='?'
request=url
params.each { |key,val|
val.gsub!(/s /,'%20') if val.is_a?(String)
request=request "#{pre}#{key}=#{val}"
pre='&'
}
result=open(request).read
end
protected
def validURL(url)
return false unless url.respond_to? :to_s
return true if url.to_s =~ /^http[s]{0,1}://[A-Za-z][A-Za-z0-9 -.]*/
return false
end
end
end - sfac, on 10/12/2007, -0/+0Thanks for digging
- hadem, on 10/12/2007, -9/+5Why were both of the above comments negative? WTF? All of the PHP fan boys automatically down grade comments just because it says something about Rails. But then comments as retarded as "I love longitude" gets a possitive rank? People need to grow up when it comes to the /- buttons on the comments.
- jimdiggity, on 10/12/2007, -9/+2i love longitude too!


What is Digg?