マッシュアップ沖縄版 おまけ:OpenSocail
- 84. require 'net/http'
require 'cgi'
require 'rexml/document'
class GNavi
attr_accessor :address, :name, :id, :lat, :lon
KEY = '4e900eb4fa92d4765040993687cdfe53'
URL = 'http://api.gnavi.co.jp/ver1/RestSearchAPI/?'
def self.?nd(params)
results = []
get(params).elements.each('response/rest') do |el|
results << self.new(el.elements["id"].text, el.elements["name"].text, el.elements["address"].text,
el.elements["latitude"].text, el.elements["longitude"].text)
end
results
end
def self.url(params)
params[:keyid] = KEY
URI.parse(URL+((params.map { |key,value| "#{key}=#{CGI::escape(value.to_s)}"}).join('&')))
end
def self.get(params)
REXML::Document.new(Net::HTTP.get(url(params)))
end
def initialize(id, name, address, lat, lon)
@id, @name, @address, @lat, @lon = id, name, address, lat, lon
end
end
- 94. $ rails okinawa -d sqlite3
$ cd okinawa
$ script/plugin install
svn://rubyforge.org/var/svn/ym4r/Plugins/GM/trunk/ym4r_gm
$ ./script/generate controller soba index
- 96. class SobaController < ApplicationController
def index
@map = GMap.new("map_div")
@map.control_init :large_map => true, :map_type => true
@map.center_zoom_init([26.21332,127.689843], 12)
end
end
- 102. class SobaController < ApplicationController
def index
@map = GMap.new("map_div")
@map.control_init(:large_map => true, :map_type => true)
@map.center_zoom_init([26.21332,127.689843], 12)
GNavi.?nd(:pref=>'PREF47', :name=>'沖縄そば').each do |o|
begin
marker = GMarker.new(
[o.lat, o.lon], :title => o.name,
:info_window => render_to_string( :partial => 'point', :locals
=> { :soba => o })
)
@map.overlay_init(marker)
rescue
end
end
end
- 133. <?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Example">
<Require feature="opensocial-0.5"/>
</ModulePrefs>
<Content type="html">
<![CDATA[
~コード~
]]>
</Content>
</Module>