class GoogleMobileMapView
PKG_VERSION = '1.0.0'
GET_URL = 'http://maps.google.com/mapprint?tstyp=4'
IMAGE_TYPE = {"gif"=>1,"png"=>2,"jpeg"=>3,"jpg"=>3}
def initialize(latitude,longitude,settings = Hash.new,points = Array.new)
@query = ""
raise StandardError.new("ArgumentError") unless set_url(latitude,longitude,settings,points)
end
private
def set_url(latitude,longitude,settings = Hash.new,points = Array.new)
if not latitude or not longitude
return false
end
@query = GET_URL + "&c=#{longitude},#{latitude}"
settings["w"] = 200 unless settings["w"]
settings["w"] = 200 unless settings["h"]
settings["z"] = 0 unless settings["z"]
@query += "&r=#{settings["w"]},#{settings["h"]}"
@query += "&z=#{settings["z"]}"
if settings["image_format"] =~ /^[1-3]$/
@image_format = settings["image_format"]
elsif IMAGE_TYPE[settings["image_format"]]
@image_format = IMAGE_TYPE[settings["image_format"]]
else
@image_format = "1"
end
@query += "&image_format=#{@image_format}"
points.each do |point|
next if not point["latitude"] or not point["longitude"]
point["iconid"] = 15 unless point["iconid"]
@query += "&l=#{point["longitude"]},#{point["latitude"]},#{point["iconid"]}"
end
return true
end
def to_s
@query
end
end
if __FILE__ == $0
points =
[
{'latitude' => 35707701,'longitude' => 139761787,'iconid' => 17},
{'latitude' => 35706847,'longitude' => 139762618,'iconid' => 18},
{'latitude' => 35706764,'longitude' => 139762515,'iconid' => 19},
]
puts GoogleMobileMapView.new(35707215,139762162,{'w' => 240,'h' => 240,'image_format' => '1'},points)
puts GoogleMobileMapView.new(35707215,139762162,{'w' => 240,'h' => 240,'image_format' => '2'},points)
puts GoogleMobileMapView.new(35707215,139762162,{'w' => 240,'h' => 240,'image_format' => '3'},points)
puts GoogleMobileMapView.new(35707215,139762162,{'w' => 240,'h' => 240,'image_format' => '4'},points)
puts GoogleMobileMapView.new(35707215,139762162,{'w' => 240,'h' => 240,'image_format' => 'gif'},points)
puts GoogleMobileMapView.new(35707215,139762162,{'w' => 240,'h' => 240,'image_format' => 'png'},points)
puts GoogleMobileMapView.new(35707215,139762162,{'w' => 240,'h' => 240,'image_format' => 'jpg'},points)
puts GoogleMobileMapView.new(35707215,139762162,{'w' => 240,'h' => 240,'image_format' => 'jpeg'},points)
puts GoogleMobileMapView.new(35707215,139762162,{'w' => 240,'h' => 240,'image_format' => 'hoge'},points)
puts GoogleMobileMapView.new(35707215,139762162,{'w' => 240,'h' => 240},points)
end