darrell-geokit 1.5.0.2 → 1.5.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/geokit/geocoders.rb +45 -34
  2. metadata +8 -18
@@ -4,7 +4,13 @@ require 'rexml/document'
4
4
  require 'yaml'
5
5
  require 'timeout'
6
6
  require 'logger'
7
- require 'json/pure'
7
+
8
+ # do this just in case
9
+ begin
10
+ ActiveSupport.nil?
11
+ rescue NameError
12
+ require 'json/pure'
13
+ end
8
14
 
9
15
  module Geokit
10
16
 
@@ -568,29 +574,34 @@ module Geokit
568
574
  logger.debug "Google geocoding. Address: #{address}. Result: #{json}"
569
575
  return self.json2GeoLoc(json, address)
570
576
  end
571
-
577
+
572
578
  def self.construct_bias_string_from_options(bias)
573
579
  if bias.is_a?(String) or bias.is_a?(Symbol)
574
580
  # country code biasing
575
581
  "&region=#{bias.to_s.downcase}"
576
582
  elsif bias.is_a?(Bounds)
577
583
  # viewport biasing
578
- "&bounds=#{bias.nw.to_s}|#{bias.se.to_s}"
584
+ Geokit::Inflector::url_escape("&bounds=#{bias.sw.to_s}|#{bias.ne.to_s}")
579
585
  end
580
586
  end
581
-
587
+
582
588
  def self.json2GeoLoc(json, address="")
583
589
  ret=nil
584
- results=JSON.parse(json, :symbolize_names => true)
590
+ begin
591
+ results=::ActiveSupport::JSON.decode(json)
592
+ rescue NameError => e
593
+ results=JSON.parse(json)
594
+ end
595
+
585
596
 
586
- if results[:status] == 'OVER_QUERY_LIMIT'
597
+ if results['status'] == 'OVER_QUERY_LIMIT'
587
598
  raise Geokit::TooManyQueriesError
588
599
  end
589
- if results[:status] == 'ZERO_RESULTS'
600
+ if results['status'] == 'ZERO_RESULTS'
590
601
  return GeoLoc.new
591
602
  end
592
603
  # this should probably be smarter.
593
- if !results[:status] == 'OK'
604
+ if !results['status'] == 'OK'
594
605
  raise Geokit::Geocoders::GeocodeError
595
606
  end
596
607
  # location_type stores additional data about the specified location.
@@ -615,35 +626,35 @@ module Geokit
615
626
  "GEOMETRIC_CENTER" => 5,
616
627
  "APPROXIMATE" => 4
617
628
  }
618
- results[:results].sort_by{|a|accuracy[a[:geometry][:location_type]]}.reverse.each do |addr|
629
+ results['results'].sort_by{|a|accuracy[a['geometry']['location_type']]}.reverse.each do |addr|
619
630
  res=GeoLoc.new
620
631
  res.provider = 'google3'
621
632
  res.success = true
622
- res.full_address = addr[:formatted_address]
623
- addr[:address_components].each do |comp|
633
+ res.full_address = addr['formatted_address']
634
+ addr['address_components'].each do |comp|
624
635
  case
625
- when comp[:types].include?("street_number")
626
- res.street_number = comp[:short_name]
627
- when comp[:types].include?("route")
628
- res.street_name = comp[:long_name]
629
- when comp[:types].include?("locality")
630
- res.city = comp[:long_name]
631
- when comp[:types].include?("administrative_area_level_1")
632
- res.state = comp[:short_name]
633
- res.province = comp[:short_name]
634
- when comp[:types].include?("postal_code")
635
- res.zip = comp[:long_name]
636
- when comp[:types].include?("country")
637
- res.country_code = comp[:short_name]
638
- res.country = comp[:long_name]
639
- when comp[:types].include?("administrative_area_level_2")
640
- res.district = comp[:long_name]
636
+ when comp['types'].include?("street_number")
637
+ res.street_number = comp['short_name']
638
+ when comp['types'].include?("route")
639
+ res.street_name = comp['long_name']
640
+ when comp['types'].include?("locality")
641
+ res.city = comp['long_name']
642
+ when comp['types'].include?("administrative_area_level_1")
643
+ res.state = comp['short_name']
644
+ res.province = comp['short_name']
645
+ when comp['types'].include?("postal_code")
646
+ res.zip = comp['long_name']
647
+ when comp['types'].include?("country")
648
+ res.country_code = comp['short_name']
649
+ res.country = comp['long_name']
650
+ when comp['types'].include?("administrative_area_level_2")
651
+ res.district = comp['long_name']
641
652
  end
642
653
  end
643
654
  if res.street_name
644
655
  res.street_address=[res.street_number,res.street_name].join(' ').strip
645
656
  end
646
- res.accuracy = accuracy[addr[:geometry][:location_type]]
657
+ res.accuracy = accuracy[addr['geometry']['location_type']]
647
658
  res.precision=%w{unknown country state state city zip zip+4 street address building}[res.accuracy]
648
659
  # try a few overrides where we can
649
660
  if res.street_name && res.precision=='city'
@@ -651,16 +662,16 @@ module Geokit
651
662
  res.accuracy = 7
652
663
  end
653
664
 
654
- res.lat=addr[:geometry][:location][:lat].to_f
655
- res.lng=addr[:geometry][:location][:lng].to_f
665
+ res.lat=addr['geometry']['location']['lat'].to_f
666
+ res.lng=addr['geometry']['location']['lng'].to_f
656
667
 
657
668
  ne=Geokit::LatLng.new(
658
- addr[:geometry][:viewport][:northeast][:lat].to_f,
659
- addr[:geometry][:viewport][:northeast][:lng].to_f
669
+ addr['geometry']['viewport']['northeast']['lat'].to_f,
670
+ addr['geometry']['viewport']['northeast']['lng'].to_f
660
671
  )
661
672
  sw=Geokit::LatLng.new(
662
- addr[:geometry][:viewport][:southwest][:lat].to_f,
663
- addr[:geometry][:viewport][:southwest][:lng].to_f
673
+ addr['geometry']['viewport']['southwest']['lat'].to_f,
674
+ addr['geometry']['viewport']['southwest']['lng'].to_f
664
675
  )
665
676
  res.suggested_bounds = Geokit::Bounds.new(sw,ne)
666
677
 
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darrell-geokit
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 5
8
- - 0
9
- - 2
10
- version: 1.5.0.2
4
+ version: 1.5.0.4
11
5
  platform: ruby
12
6
  authors:
13
7
  - Andre Lewis and Bill Eisenhauer
@@ -20,16 +14,14 @@ default_executable:
20
14
  dependencies:
21
15
  - !ruby/object:Gem::Dependency
22
16
  name: json_pure
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
25
20
  requirements:
26
21
  - - ">="
27
22
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
23
  version: "0"
31
- type: :runtime
32
- version_requirements: *id001
24
+ version:
33
25
  description: Geokit Gem
34
26
  email:
35
27
  - andre@earthcode.com / bill_eisenhauer@yahoo.com
@@ -71,20 +63,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
63
  requirements:
72
64
  - - ">="
73
65
  - !ruby/object:Gem::Version
74
- segments:
75
- - 0
76
66
  version: "0"
67
+ version:
77
68
  required_rubygems_version: !ruby/object:Gem::Requirement
78
69
  requirements:
79
70
  - - ">="
80
71
  - !ruby/object:Gem::Version
81
- segments:
82
- - 0
83
72
  version: "0"
73
+ version:
84
74
  requirements: []
85
75
 
86
76
  rubyforge_project: geokit
87
- rubygems_version: 1.3.6
77
+ rubygems_version: 1.3.5
88
78
  signing_key:
89
79
  specification_version: 2
90
80
  summary: none