Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

restore street view embed features

  • Loading branch information...
commit 3c53c5bb3b3152182fd409a4a831860d1fb29782 1 parent 7afad59
@greatseth authored
View
4 CHANGELOG
@@ -1,6 +1,4 @@
-v2.3. Added Support for Street View. Renamed method reverse_geocoding to reverse_location.
-
-v2.2. Added Support for Reverse Geocoding.
+v2.2. Added reverse locate and optional street view embed features. Thanks to Fernando Barajas and Peter Gassner!
v2.1. Added a LICENSE and RubyForge publishing support. Fixed Rakefile.
View
15 Manifest
@@ -1,19 +1,32 @@
CHANGELOG
-google-geo.gemspec
+lib/google/geo/address/street_view.rb
+lib/google/geo/address.rb
+lib/google/geo/params.rb
+lib/google/geo/parser.rb
+lib/google/geo/response.rb
lib/google/geo.rb
LICENSE
Manifest
Rakefile
README.textile
+script/test_street_view.rb
test/fixtures/invalid_map_key.xml
test/fixtures/missing_address.xml
+test/fixtures/reverse_locate_602.xml
+test/fixtures/reverse_locate_success.xml
test/fixtures/server_error.xml
+test/fixtures/streetview_success.xml
test/fixtures/success.xml
+test/fixtures/success_english.xml
+test/fixtures/success_german.xml
test/fixtures/success_with_multiple_addresses.xml
test/fixtures/too_many_queries.xml
test/fixtures/unavailable_address.xml
test/fixtures/unknown_address.xml
test/geo_test.rb
+test/locate_street_view_test.rb
+test/reverse_locate_test.rb
+test/test_helper.rb
vendor/mocha-0.4.0/COPYING
vendor/mocha-0.4.0/examples/misc.rb
vendor/mocha-0.4.0/examples/mocha.rb
View
19 README.textile
@@ -26,25 +26,18 @@ In the case of sufficiently vague queries, Google::Geo will return more than one
You can reverse geocode:
- geo = Google::Geo.new API_KEY
- location = geo.reverse_locate(:lat => 33.998671, :lon => -118.075926).first
+ location = geo.locate(33.998671, -118.075926).first
location.city # => Pico Rivera
location.state # => CA
location.zip # => 90660
location.country # => US
location.full_address # => 4952-4958 Tobias Ave, Pico Rivera, CA 90660, USA
-You can locate street view
+You can optionally enable the ability to get street view embed HTML for an Address:
- geo = Google::Geo.new API_KEY
address = geo.locate('1600 Amphitheatre Parkway, Mountain View, CA').first
- address.street_view # => Returns an HTML Flash Embed Tag to display street view
+ address.street_view_html # => Returns an HTML Flash Embed Tag to display street view
-
- geo = Google::Geo.new API_KEY
- location = geo.reverse_locate(:lat => 33.998671, :lon => -118.075926).first
- location.street_view # => Returns street view for location
-
h2. Options
If you need to get the results in another language, you can set it like so:
@@ -57,9 +50,9 @@ where the language code can be anything listed on http://spreadsheets.google.com
h2. Contributors
* Seth Thomas Rasmussen - "http://greatseth.com":http://greatseth.com
-* Fernando Barajas - "http://fernyb.net":http://fernyb.net
-* Peter Gassner - "http://www.naehrstoff.ch":http://www.naehrstoff.ch
+* Fernando Barajas - "http://fernyb.net":http://fernyb.net
+* Peter Gassner - "http://www.naehrstoff.ch":http://www.naehrstoff.ch
h2. License
-(c) 2007-2008 Seth Thomas Rasmussen and released under the WTFPL. See the LICENSE file for details.
+(c) 2007-2009 Seth Thomas Rasmussen and released under the WTFPL. See the LICENSE file for details.
View
11 Rakefile
@@ -3,9 +3,12 @@ README = File.readlines "#{File.dirname __FILE__}/README.textile"
require "echoe"
Echoe.new "google-geo" do |p|
- p.author = "Seth Thomas Rasmussen"
- p.email = "sethrasmussen@gmail.com"
- p.url = "http://github.com/greatseth/google-geo"
+ p.author = "Seth Thomas Rasmussen"
+ p.email = "sethrasmussen@gmail.com"
+ p.url = "http://github.com/greatseth/google-geo"
p.summary = README[2]
- p.project = "greatseth"
+
+ # p.project = "greatseth"
+
+ p.ignore_pattern = ["google-geo-streetview.html"]
end
View
163 google-geo.gemspec
@@ -1,139 +1,32 @@
+# -*- encoding: utf-8 -*-
-# Gem::Specification for Google-geo-2.1
-# Originally generated by Echoe
+Gem::Specification.new do |s|
+ s.name = %q{google-geo}
+ s.version = "2.2"
---- !ruby/object:Gem::Specification
-name: google-geo
-version: !ruby/object:Gem::Version
- version: "2.1"
-platform: ruby
-authors:
-- Seth Thomas Rasmussen
-autorequire:
-bindir: bin
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Seth Thomas Rasmussen"]
+ s.date = %q{2009-04-13}
+ s.description = %q{A simple, elegant library for getting geocoding information from Google Maps. Very much inspired by the google-geocode gem, but completely dependency free!}
+ s.email = %q{sethrasmussen@gmail.com}
+ s.extra_rdoc_files = ["CHANGELOG", "lib/google/geo/address/street_view.rb", "lib/google/geo/address.rb", "lib/google/geo/params.rb", "lib/google/geo/parser.rb", "lib/google/geo/response.rb", "lib/google/geo.rb", "LICENSE", "README.textile"]
+ s.files = ["CHANGELOG", "lib/google/geo/address/street_view.rb", "lib/google/geo/address.rb", "lib/google/geo/params.rb", "lib/google/geo/parser.rb", "lib/google/geo/response.rb", "lib/google/geo.rb", "LICENSE", "Manifest", "Rakefile", "README.textile", "script/test_street_view.rb", "test/fixtures/invalid_map_key.xml", "test/fixtures/missing_address.xml", "test/fixtures/reverse_locate_602.xml", "test/fixtures/reverse_locate_success.xml", "test/fixtures/server_error.xml", "test/fixtures/streetview_success.xml", "test/fixtures/success.xml", "test/fixtures/success_english.xml", "test/fixtures/success_german.xml", "test/fixtures/success_with_multiple_addresses.xml", "test/fixtures/too_many_queries.xml", "test/fixtures/unavailable_address.xml", "test/fixtures/unknown_address.xml", "test/geo_test.rb", "test/locate_street_view_test.rb", "test/reverse_locate_test.rb", "test/test_helper.rb", "vendor/mocha-0.4.0/COPYING", "vendor/mocha-0.4.0/examples/misc.rb", "vendor/mocha-0.4.0/examples/mocha.rb", "vendor/mocha-0.4.0/examples/stubba.rb", "vendor/mocha-0.4.0/lib/mocha/any_instance_method.rb", "vendor/mocha-0.4.0/lib/mocha/auto_verify.rb", "vendor/mocha-0.4.0/lib/mocha/central.rb", "vendor/mocha-0.4.0/lib/mocha/class_method.rb", "vendor/mocha-0.4.0/lib/mocha/expectation.rb", "vendor/mocha-0.4.0/lib/mocha/expectation_error.rb", "vendor/mocha-0.4.0/lib/mocha/infinite_range.rb", "vendor/mocha-0.4.0/lib/mocha/inspect.rb", "vendor/mocha-0.4.0/lib/mocha/instance_method.rb", "vendor/mocha-0.4.0/lib/mocha/metaclass.rb", "vendor/mocha-0.4.0/lib/mocha/mock.rb", "vendor/mocha-0.4.0/lib/mocha/mock_methods.rb", "vendor/mocha-0.4.0/lib/mocha/object.rb", "vendor/mocha-0.4.0/lib/mocha/pretty_parameters.rb", "vendor/mocha-0.4.0/lib/mocha/setup_and_teardown.rb", "vendor/mocha-0.4.0/lib/mocha/standalone.rb", "vendor/mocha-0.4.0/lib/mocha/test_case_adapter.rb", "vendor/mocha-0.4.0/lib/mocha.rb", "vendor/mocha-0.4.0/lib/mocha_standalone.rb", "vendor/mocha-0.4.0/lib/stubba.rb", "vendor/mocha-0.4.0/MIT-LICENSE", "vendor/mocha-0.4.0/Rakefile", "vendor/mocha-0.4.0/README", "vendor/mocha-0.4.0/RELEASE", "vendor/mocha-0.4.0/test/active_record_test_case.rb", "vendor/mocha-0.4.0/test/all_tests.rb", "vendor/mocha-0.4.0/test/execution_point.rb", "vendor/mocha-0.4.0/test/method_definer.rb", "vendor/mocha-0.4.0/test/mocha/any_instance_method_test.rb", "vendor/mocha-0.4.0/test/mocha/auto_verify_test.rb", "vendor/mocha-0.4.0/test/mocha/central_test.rb", "vendor/mocha-0.4.0/test/mocha/class_method_test.rb", "vendor/mocha-0.4.0/test/mocha/expectation_test.rb", "vendor/mocha-0.4.0/test/mocha/infinite_range_test.rb", "vendor/mocha-0.4.0/test/mocha/inspect_test.rb", "vendor/mocha-0.4.0/test/mocha/metaclass_test.rb", "vendor/mocha-0.4.0/test/mocha/mock_methods_test.rb", "vendor/mocha-0.4.0/test/mocha/mock_test.rb", "vendor/mocha-0.4.0/test/mocha/object_test.rb", "vendor/mocha-0.4.0/test/mocha/pretty_parameters_test.rb", "vendor/mocha-0.4.0/test/mocha/setup_and_teardown_test.rb", "vendor/mocha-0.4.0/test/mocha_acceptance_test.rb", "vendor/mocha-0.4.0/test/mocha_test_result_integration_test.rb", "vendor/mocha-0.4.0/test/standalone_acceptance_test.rb", "vendor/mocha-0.4.0/test/stubba_acceptance_test.rb", "vendor/mocha-0.4.0/test/stubba_integration_test.rb", "vendor/mocha-0.4.0/test/stubba_test_result_integration_test.rb", "vendor/mocha-0.4.0/test/test_helper.rb", "google-geo.gemspec"]
+ s.has_rdoc = true
+ s.homepage = %q{http://github.com/greatseth/google-geo}
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Google-geo", "--main", "README.textile"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{google-geo}
+ s.rubygems_version = %q{1.3.1}
+ s.summary = %q{A simple, elegant library for getting geocoding information from Google Maps. Very much inspired by the google-geocode gem, but completely dependency free!}
+ s.test_files = ["test/geo_test.rb", "test/reverse_locate_test.rb", "test/test_helper.rb"]
-date: 2008-09-29 00:00:00 -04:00
-default_executable:
-dependencies:
-- !ruby/object:Gem::Dependency
- name: echoe
- type: :development
- version_requirement:
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: "0"
- version:
-description: A simple, elegant library for getting geocoding information from Google Maps. Very much inspired by the google-geocode gem, but completely dependency free!
-email: sethrasmussen@gmail.com
-executables: []
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 2
-extensions: []
-
-extra_rdoc_files:
-- CHANGELOG
-- lib/google/geo.rb
-- LICENSE
-- README.textile
-files:
-- CHANGELOG
-- lib/google/geo.rb
-- LICENSE
-- Manifest
-- Rakefile
-- README.textile
-- test/fixtures/invalid_map_key.xml
-- test/fixtures/missing_address.xml
-- test/fixtures/server_error.xml
-- test/fixtures/success.xml
-- test/fixtures/success_with_multiple_addresses.xml
-- test/fixtures/too_many_queries.xml
-- test/fixtures/unavailable_address.xml
-- test/fixtures/unknown_address.xml
-- test/geo_test.rb
-- vendor/mocha-0.4.0/COPYING
-- vendor/mocha-0.4.0/examples/misc.rb
-- vendor/mocha-0.4.0/examples/mocha.rb
-- vendor/mocha-0.4.0/examples/stubba.rb
-- vendor/mocha-0.4.0/lib/mocha/any_instance_method.rb
-- vendor/mocha-0.4.0/lib/mocha/auto_verify.rb
-- vendor/mocha-0.4.0/lib/mocha/central.rb
-- vendor/mocha-0.4.0/lib/mocha/class_method.rb
-- vendor/mocha-0.4.0/lib/mocha/expectation.rb
-- vendor/mocha-0.4.0/lib/mocha/expectation_error.rb
-- vendor/mocha-0.4.0/lib/mocha/infinite_range.rb
-- vendor/mocha-0.4.0/lib/mocha/inspect.rb
-- vendor/mocha-0.4.0/lib/mocha/instance_method.rb
-- vendor/mocha-0.4.0/lib/mocha/metaclass.rb
-- vendor/mocha-0.4.0/lib/mocha/mock.rb
-- vendor/mocha-0.4.0/lib/mocha/mock_methods.rb
-- vendor/mocha-0.4.0/lib/mocha/object.rb
-- vendor/mocha-0.4.0/lib/mocha/pretty_parameters.rb
-- vendor/mocha-0.4.0/lib/mocha/setup_and_teardown.rb
-- vendor/mocha-0.4.0/lib/mocha/standalone.rb
-- vendor/mocha-0.4.0/lib/mocha/test_case_adapter.rb
-- vendor/mocha-0.4.0/lib/mocha.rb
-- vendor/mocha-0.4.0/lib/mocha_standalone.rb
-- vendor/mocha-0.4.0/lib/stubba.rb
-- vendor/mocha-0.4.0/MIT-LICENSE
-- vendor/mocha-0.4.0/Rakefile
-- vendor/mocha-0.4.0/README
-- vendor/mocha-0.4.0/RELEASE
-- vendor/mocha-0.4.0/test/active_record_test_case.rb
-- vendor/mocha-0.4.0/test/all_tests.rb
-- vendor/mocha-0.4.0/test/execution_point.rb
-- vendor/mocha-0.4.0/test/method_definer.rb
-- vendor/mocha-0.4.0/test/mocha/any_instance_method_test.rb
-- vendor/mocha-0.4.0/test/mocha/auto_verify_test.rb
-- vendor/mocha-0.4.0/test/mocha/central_test.rb
-- vendor/mocha-0.4.0/test/mocha/class_method_test.rb
-- vendor/mocha-0.4.0/test/mocha/expectation_test.rb
-- vendor/mocha-0.4.0/test/mocha/infinite_range_test.rb
-- vendor/mocha-0.4.0/test/mocha/inspect_test.rb
-- vendor/mocha-0.4.0/test/mocha/metaclass_test.rb
-- vendor/mocha-0.4.0/test/mocha/mock_methods_test.rb
-- vendor/mocha-0.4.0/test/mocha/mock_test.rb
-- vendor/mocha-0.4.0/test/mocha/object_test.rb
-- vendor/mocha-0.4.0/test/mocha/pretty_parameters_test.rb
-- vendor/mocha-0.4.0/test/mocha/setup_and_teardown_test.rb
-- vendor/mocha-0.4.0/test/mocha_acceptance_test.rb
-- vendor/mocha-0.4.0/test/mocha_test_result_integration_test.rb
-- vendor/mocha-0.4.0/test/standalone_acceptance_test.rb
-- vendor/mocha-0.4.0/test/stubba_acceptance_test.rb
-- vendor/mocha-0.4.0/test/stubba_integration_test.rb
-- vendor/mocha-0.4.0/test/stubba_test_result_integration_test.rb
-- vendor/mocha-0.4.0/test/test_helper.rb
-- google-geo.gemspec
-has_rdoc: true
-homepage: http://github.com/greatseth/google-geo
-post_install_message:
-rdoc_options:
-- --line-numbers
-- --inline-source
-- --title
-- Google-geo
-- --main
-- README.textile
-require_paths:
-- lib
-required_ruby_version: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: "0"
- version:
-required_rubygems_version: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: "1.2"
- version:
-requirements: []
-
-rubyforge_project: greatseth
-rubygems_version: 1.2.0
-specification_version: 2
-summary: A simple, elegant library for getting geocoding information from Google Maps. Very much inspired by the google-geocode gem, but completely dependency free!
-test_files:
-- test/geo_test.rb
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
View
28 lib/google/geo/address/street_view.rb
@@ -0,0 +1,28 @@
+require "google/geo"
+
+module Google
+class Geo
+class Address
+ # This is a shady method which relies on an unofficial Google API.
+ # Use at your own risk!
+ def street_view_html(options = {})
+%{<embed id="#{options[:id] or 'google-geo-streetview'}"
+ style="#{options[:style]}"
+ src="http://maps.google.com/mapfiles/cb/googlepano.066.swf"
+ quality="high" wmode="opaque" swliveconnect="false"
+ allowscriptaccess="always" type="application/x-shockwave-flash"
+ pluginspage="http://www.macromedia.com/go/getflashplayer"
+ scale="noscale" salign="lt"
+ flashvars="panoId=#{street_view_pano_id}&amp;directionMap=N:N,W:W,S:S,E:E,NW:NW,NE:NE,SW:SW,SE:SE&amp;yaw=0&amp;zoom=0&amp;browser=3&amp;pitch=5&amp;viewerId=1&amp;context=api&amp;animateOnLoad=false&amp;useSsl=false"
+></embed>}.gsub("\n", "").squeeze(" ")
+ end
+
+private
+ def street_view_pano_id
+ url = "http://maps.google.com/cbk?output=xml&oe=utf-8&cb_client=api&ll=#{lat},#{lng}"
+ # "&callback=_xdc_._0fqdyf9p2"
+ open(url).read.slice(/pano_id="([^"]+)"/, 1)
+ end
+end
+end
+end
View
27 script/test_street_view.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+load File.dirname(__FILE__) + "/../.irbrc"
+enable_street_view
+
+g = new_geo
+a = g.locate(*ARGV).first
+
+require "tempfile"
+
+p = File.expand_path "google-geo-streetview.html"
+
+File.open(p, "w") do |f|
+ html = a.street_view_html(
+ :id => "TEST",
+ :style => "width:640px; height:480px"
+ )
+ f.puts html
+end
+
+raise "wtf" and exit unless File.exist? p
+
+require "rubygems"
+require "launchy"
+Launchy::Browser.run "file://#{p}"
+
+puts "created test file at #{p}"
View
61 test/locate_street_view_test.rb
@@ -1,61 +0,0 @@
-__END__
-
-require "test_helper"
-
-class Google::GeoTest < Test::Unit::TestCase
- def setup
- @geo = Google::Geo.new 'API_KEY'
- end
-
- def test_streetview_should_not_be_nil
- @geo.expects(:open).
- # with("http://maps.google.com/cbk?output=xml&oe=utf-8&cb_client=api&ll=34.154961,-118.25514&callback=_xdc_._0fqdyf9p2").
- returns(response(:streetview_success))
-
- street = @geo.locate(:lat => 34.154961, :lng => -118.25514)
- assert_not_nil street
- end
-
- def test_should_have_html_embed_tag
- @geo.expects(:open).
- with("http://maps.google.com/cbk?output=xml&oe=utf-8&cb_client=api&ll=34.154961,-118.25514&callback=_xdc_._0fqdyf9p2").
- returns(response(:streetview_success))
-
- street = @geo.locate(:lat => 34.154961, :lng => -118.25514)
- assert_not_nil street.scan(/\<embed.*\>.*\<\/embed\>/)
- assert_not_nil street.scan(/panoId=([a-zA-Z0-9\-_]+)/)
- end
-
- def test_reverse_location_should_have_streetview
- @geo.expects(:open).
- with("http://maps.google.com/maps/geo?ll=34.154961,-118.25514&key=API_KEY&output=xml&hl=en&oe=utf-8").
- returns(response(:locate_success))
-
- location = @geo.locate(:lat => 34.154961, :lon => -118.25514).first
-
- Google::Geo.any_instance.expects(:open).
- with("http://maps.google.com/cbk?output=xml&oe=utf-8&cb_client=api&ll=33.9986972,-118.0760384&callback=_xdc_._0fqdyf9p2").
- returns(response(:streetview_success)).at_most(3)
-
- assert_not_nil location.street_view
- assert_not_nil location.street_view.scan(/\<embed.*\>.*\<\/embed\>/)
- assert_not_nil location.street_view.scan(/panoId=([a-zA-Z0-9\-_]+)/)
- end
-
- def test_locate_should_have_streetview
- @geo.expects(:open).
- with("http://maps.google.com/maps/geo?q=1600%20Amphitheatre%20Parkway,%20Mountain%20View,%20CA&key=API_KEY&output=xml&hl=en&oe=utf-8").
- returns(response(:success))
-
- query = '1600 Amphitheatre Parkway, Mountain View, CA'
- address = @geo.locate(query).first
-
- Google::Geo.any_instance.expects(:open).
- with("http://maps.google.com/cbk?output=xml&oe=utf-8&cb_client=api&ll=37.423021,-122.083739&callback=_xdc_._0fqdyf9p2").
- returns(response(:streetview_success)).at_most(3)
-
- assert_not_nil address.street_view
- assert_not_nil address.street_view.scan(/\<embed.*\>.*\<\/embed\>/)
- assert_not_nil address.street_view.scan(/panoId=([a-zA-Z0-9\-_]+)/)
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.