Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update our fork to 1.6.5 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ nbproject
*.swp
Gemfile.lock
*.idea
coverage
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# http://about.travis-ci.org/docs/user/languages/ruby/

language: ruby
#bundler_args: --without development
rvm:
- ree
- 1.8.7
- 1.9.2
- 1.9.3

- 2.0.0
script: "bundle exec rake coverage"
before_install:
- gem install bundler
notifications:
email:
- [email protected]
37 changes: 32 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
* Fix a bug with UTF-8 encoded locations by levaraging URI::escape instead of CGI::escape.

## GEOKIT GEM DESCRIPTION
Geokit
======

[![Gem Version](https://badge.fury.io/rb/geokit.png)](http://badge.fury.io/rb/geokit)
[![Build Status](https://travis-ci.org/geokit/geokit.png?branch=master)](https://travis-ci.org/geokit/geokit)
[![Coverage Status](https://coveralls.io/repos/geokit/geokit-rails3/badge.png)](https://coveralls.io/r/geokit/geokit)
[![Dependency Status](https://gemnasium.com/geokit/geokit.png)](https://gemnasium.com/geokit/geokit)
[![Code Climate](https://codeclimate.com/github/geokit/geokit.png)](https://codeclimate.com/github/geokit/geokit)

## DESCRIPTION

The Geokit gem provides:

Expand All @@ -12,11 +22,10 @@ The Geokit gem provides:
* Rectangular bounds calculations: is a point within a given rectangular bounds?
* Heading and midpoint calculations

Combine this gem with the [geokit-rails plugin](https://github.com/imajes/geokit-rails) to get location-based finders for your Rails app.
Combine this gem with the [geokit-rails plugin](https://github.com/geokit/geokit-rails) to get location-based finders for your Rails app.

* Geokit main site [http://rubygeokit.org/](http://rubygeokit.org).
* Repository at Github: [https://github.com/imajes/geokit](https://github.com/imajes/geokit).
* RDoc pages: [http://rdoc.info/github/imajes/geokit/master/frames](http://rdoc.info/github/imajes/geokit/master/frames)
* Repository at Github: [https://github.com/geokit/geokit](https://github.com/geokit/geokit).
* RDoc pages: [http://rdoc.info/github/geokit/geokit/master/frames](http://rdoc.info/github/geokit/geokit/master/frames)
* Follow the Google Group for updates and discussion on Geokit: [http://groups.google.com/group/geokit](http://groups.google.com/group/geokit)

## INSTALL
Expand All @@ -25,6 +34,7 @@ Combine this gem with the [geokit-rails plugin](https://github.com/imajes/geokit-

## QUICK START

```ruby
irb> require 'rubygems'
irb> require 'geokit'
irb> a=Geokit::Geocoders::YahooGeocoder.geocode '140 Market St, San Francisco, CA'
Expand All @@ -43,6 +53,7 @@ Combine this gem with the [geokit-rails plugin](https://github.com/imajes/geokit-
irb(main):008:0> d=c.endpoint(90,10) # what's 10 miles to the east of c?
irb> d.ll
=> "37.7897825005142,-122.223214776155"
```

FYI, that `.ll` method means "latitude longitude".

Expand All @@ -52,6 +63,7 @@ See the RDOC more more ... there are also operations on rectangular bounds (e.g.

If you're using this gem by itself, here are the configuration options:

```ruby
# These defaults are used in Geokit::Mappable.distance_to and in acts_as_mappable
Geokit::default_units = :miles
Geokit::default_formula = :sphere
Expand Down Expand Up @@ -116,8 +128,9 @@ If you're using this gem by itself, here are the configuration options:
# The IP provider order. Valid symbols are :ip,:geo_plugin.
# As before, make sure you read up on relevant Terms of Use for each.
# Geokit::Geocoders::ip_provider_order = [:external,:geo_plugin,:ip]
```

If you're using this gem with the [geokit-rails plugin](https://github.com/imajes/geokit-rails), the plugin
If you're using this gem with the [geokit-rails plugin](https://github.com/geokit/geokit-rails), the plugin
creates a template with these settings and places it in `config/initializers/geokit_config.rb`.

## SUPPORTED GEOCODERS
Expand All @@ -139,6 +152,7 @@ creates a template with these settings and places it in `config/initializers/geo

The Google Geocoder sports a number of useful tricks that elevate it a little bit above the rest of the currently supported geocoders. For starters, it returns a `suggested_bounds` property for all your geocoded results, so you can more easily decide where and how to center a map on the places you geocode. Here's a quick example:

```ruby
irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('140 Market St, San Francisco, CA')
irb> pp res.suggested_bounds
#<Geokit::Bounds:0x53b36c
Expand All @@ -150,39 +164,49 @@ In addition, you can use viewport or country code biasing to make sure the geoco
irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse')
irb> res.full_address
=> "Syracuse, NY, USA"
```

Not exactly what we were looking for. We know that Syracuse is in Italy, so we can tell the Google Geocoder to prefer results from Italy first, and then wander the Syracuses of the world. To do that, we have to pass Italy's ccTLD (country code top-level domain) to the `:bias` option of the `geocode` method. You can find a comprehensive list of all ccTLDs here: http://en.wikipedia.org/wiki/CcTLD.

```ruby
irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse', :bias => 'it')
irb> res.full_address
=> "Syracuse, Italy"
```

Alternatively, we can speficy the geocoding bias as a bounding box object. Say we wanted to geocode the Winnetka district in Los Angeles.

```ruby
irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka')
irb> res.full_address
=> "Winnetka, IL, USA"
```

Not it. What we can do is tell the geocoder to return results only from in and around LA.

```ruby
irb> la_bounds = Geokit::Geocoders::GoogleGeocoder.geocode('Los Angeles').suggested_bounds
irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka', :bias => la_bounds)
irb> res.full_address
=> "Winnetka, California, USA"
```


### The Multigeocoder
Multi Geocoder - provides failover for the physical location geocoders, and also IP address geocoders. Its configured by setting Geokit::Geocoders::provider_order, and Geokit::Geocoders::ip_provider_order. You should call the Multi-Geocoder with its :geocode method, supplying one address parameter which is either a real street address, or an ip address. For example:

```ruby
Geokit::Geocoders::MultiGeocoder.geocode("900 Sycamore Drive")

Geokit::Geocoders::MultiGeocoder.geocode("12.12.12.12")
```

## MULTIPLE RESULTS
Some geocoding services will return multple results if the there isn't one clear result.
Geoloc can capture multiple results through its "all" method. Currently only the Google geocoder
supports multiple results:

```ruby
irb> geo=Geokit::Geocoders::GoogleGeocoder.geocode("900 Sycamore Drive")
irb> geo.full_address
=> "900 Sycamore Dr, Arkadelphia, AR 71923, USA"
Expand All @@ -192,6 +216,7 @@ supports multiple results:
900 Sycamore Dr, Burkburnett, TX 76354, USA
900 Sycamore Dr, TN 38361, USA
....
```

geo.all is just an array of additional Geolocs, so do what you want with it. If you call .all on a
geoloc that doesn't have any additional results, you will get an array of one.
Expand Down Expand Up @@ -223,6 +248,7 @@ do_geocode.
If you would like to write your own geocoders, you can do so by requiring 'geokit' or 'geokit/geocoders.rb' in a new file and subclassing the base class (which is class "Geocoder").
You must then also require such extenal file back in your main geokit configuration.

```ruby
require "geokit"

module Geokit
Expand All @@ -247,6 +273,7 @@ You must then also require such extenal file back in your main geokit configurat

end
end
```

## GOOGLE GROUP

Expand Down
9 changes: 8 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
require "bundler/gem_tasks"
require 'rake/testtask'

task :default => :test
task :default do
end

Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/test*.rb']
t.verbose = true
end

desc "Generate SimpleCov test coverage and open in your browser"
task :coverage do
ENV['COVERAGE'] = 'true'
Rake::Task['test'].invoke
end
15 changes: 15 additions & 0 deletions ext/mkrf_conf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rubygems'
require 'rubygems/command.rb'
require 'rubygems/dependency_installer.rb'
begin
Gem::Command.build_args = ARGV
rescue NoMethodError
end
inst = Gem::DependencyInstaller.new
begin
if RUBY_VERSION < "1.9"
inst.install "iconv"
end
rescue
exit(1)
end
71 changes: 30 additions & 41 deletions geokit.gemspec
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'geokit/version'

Gem::Specification.new do |s|
s.name = "geokit"
s.version = Geokit::VERSION
s.authors = ["James Cox, Andre Lewis & Bill Eisenhauer"]
s.email = ["[email protected]"]
s.homepage = "https://github.com/imajes/geokit-gem"

s.summary = %q{Geokit: encoding and distance calculation gem}
s.description = %q{Geokit provides geocoding and distance calculation in an easy-to-use API}

s.rubyforge_project = "geokit"

s.has_rdoc = true
s.rdoc_options = ["--main", "README.markdown"]
s.extra_rdoc_files = ["README.markdown"]

s.files = [
"README.markdown", "Rakefile", "lib/geokit.rb", "lib/geokit/geocoders.rb", "lib/geokit/inflectors.rb",
"lib/geokit/mappable.rb", "lib/geokit/multi_geocoder.rb", "lib/geokit/services/ca_geocoder.rb",
"lib/geokit/services/fcc.rb", "lib/geokit/services/geo_plugin.rb", "lib/geokit/services/geonames.rb",
"lib/geokit/services/google.rb", "lib/geokit/services/google3.rb", "lib/geokit/services/ip.rb",
"lib/geokit/services/us_geocoder.rb", "lib/geokit/services/yahoo.rb", "lib/geokit/version.rb"
]

s.test_files = [
"test/test_base_geocoder.rb", "test/test_bounds.rb", "test/test_ca_geocoder.rb",
"test/test_geoloc.rb", "test/test_geoplugin_geocoder.rb", "test/test_google_geocoder3.rb",
"test/test_google_geocoder.rb", "test/test_google_reverse_geocoder.rb", "test/test_inflector.rb",
"test/test_ipgeocoder.rb", "test/test_latlng.rb", "test/test_multi_geocoder.rb",
"test/test_multi_ip_geocoder.rb", "test/test_us_geocoder.rb", "test/test_yahoo_geocoder.rb"
]

s.require_paths = ["lib"]

# specify any dependencies here; for example:
s.add_dependency 'multi_json', '>= 1.3.2'
s.add_development_dependency 'rake'
s.add_development_dependency 'mocha'
Gem::Specification.new do |spec|
spec.name = "geokit"
spec.version = Geokit::VERSION
spec.authors = ["Michael Noack, James Cox, Andre Lewis & Bill Eisenhauer"]
spec.email = ["[email protected]"]
spec.description = %q{Geokit provides geocoding and distance calculation in an easy-to-use API}
spec.summary = %q{Geokit: encoding and distance calculation gem}
spec.homepage = "https://github.com/geokit/geokit"
spec.license = "MIT"

spec.has_rdoc = true
spec.rdoc_options = ["--main", "README.markdown"]
spec.extra_rdoc_files = ["README.markdown"]
spec.extensions = 'ext/mkrf_conf.rb'

spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency "multi_json", ">= 1.3.2"
spec.add_development_dependency "bundler", "> 1.0"
spec.add_development_dependency 'simplecov'
spec.add_development_dependency "simplecov-rcov"
spec.add_development_dependency 'rake'
spec.add_development_dependency 'mocha'
spec.add_development_dependency 'coveralls'
end

6 changes: 6 additions & 0 deletions lib/geokit/mappable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,12 @@ def to_yaml_properties
(instance_variables - ['@all', :@all]).sort
end

def encode_with(coder)
to_yaml_properties.each do |name|
coder[name[1..-1].to_s] = instance_variable_get(name.to_s)
end
end

# Returns a string representation of the instance.
def to_s
"Provider: #{provider}\nStreet: #{street_address}\nCity: #{city}\nState: #{state}\nZip: #{zip}\nLatitude: #{lat}\nLongitude: #{lng}\nCountry: #{country_code}\nSuccess: #{success}"
Expand Down
8 changes: 7 additions & 1 deletion lib/geokit/services/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,16 @@ def self.construct_bias_string_from_options(bias)
"&gl=#{bias.to_s.downcase}"
elsif bias.is_a?(Bounds)
# viewport biasing
"&ll=#{bias.center.ll}&spn=#{bias.to_span.ll}"
"&ll=#{precise_ll(bias.center)}&spn=#{precise_ll(bias.to_span)}"
end
end

# Precision to 6 decimal places as per:
# https://developers.google.com/maps/documentation/staticmaps/?hl=en#Latlons
def self.precise_ll(loc)
"#{"%.6f" % loc.lat},#{"%.6f" % loc.lng}"
end

def self.xml2GeoLoc(xml, address="")
doc=REXML::Document.new(xml)

Expand Down
Loading