geokit_aws_geoplaces 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +56 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +41 -0
- data/README.md +50 -0
- data/geokit_aws_geoplaces.gemspec +26 -0
- data/lib/geokit_aws_geoplaces.rb +100 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d7b6a91eb14109e3e9e66a57d04861293a9200a8348a7a3627df8f618218f6e3
|
4
|
+
data.tar.gz: 246a5051dd552f2922e922bfe7f01505db762bd47ecf35fdb707d33a5ca32481
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b462e66a8e3f950d918fda6159d7628b1afa32c2b768d69b98d652f851e8a7245618c8a0d5f85e35d7a1bd1939ca1fb93bbf38918bd44045091e6236da5c47b2
|
7
|
+
data.tar.gz: 798ecbe13e512e4c4798664b624bfdb486d88d58b980ad6d467816fedf484050624141beee9e617dd870ec7f93a7dbc0651135dcefec91483677f9905ee503bf
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
Gemfile.lock
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
geokit_aws_geoplaces (0.0.1)
|
5
|
+
aws-sdk-geoplaces
|
6
|
+
geokit
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
aws-eventstream (1.4.0)
|
12
|
+
aws-partitions (1.1126.0)
|
13
|
+
aws-sdk-core (3.226.2)
|
14
|
+
aws-eventstream (~> 1, >= 1.3.0)
|
15
|
+
aws-partitions (~> 1, >= 1.992.0)
|
16
|
+
aws-sigv4 (~> 1.9)
|
17
|
+
base64
|
18
|
+
jmespath (~> 1, >= 1.6.1)
|
19
|
+
logger
|
20
|
+
aws-sdk-geoplaces (1.8.0)
|
21
|
+
aws-sdk-core (~> 3, >= 3.225.0)
|
22
|
+
aws-sigv4 (~> 1.5)
|
23
|
+
aws-sigv4 (1.12.1)
|
24
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
25
|
+
base64 (0.3.0)
|
26
|
+
geokit (1.14.0)
|
27
|
+
jmespath (1.6.2)
|
28
|
+
logger (1.7.0)
|
29
|
+
rake (13.3.0)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
x86_64-linux
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler
|
37
|
+
geokit_aws_geoplaces!
|
38
|
+
rake
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
2.6.2
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# geokit_aws_geoplaces
|
2
|
+
Geokit module to use AWS GeoPlaces service for geocoding
|
3
|
+
|
4
|
+
|
5
|
+
Custom [geokit](https://github.com/geokit/geokit) geocoder for [AWS Geoplaces](https://aws.amazon.com/location/) service.
|
6
|
+
|
7
|
+
[API Documentation](https://docs.aws.amazon.com/cli/latest/reference/geo-places/)
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'geokit_aws_geoplaces'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install geokit_aws_geoplaces
|
23
|
+
|
24
|
+
## Configuration
|
25
|
+
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# This is your AWS credentials. Setting it up is beyond the scope of this
|
29
|
+
# document, but be sure that your IAM profile is allowed to use the GeoPlaces service
|
30
|
+
# See https://aws.amazon.com/location/
|
31
|
+
Geokit::Geocoders::AwsGeospacesGeocoder.region = 'your-aws-region (us-east-1?)'
|
32
|
+
Geokit::Geocoders::AwsGeospacesGeocoder.access_key_id = 'YOUR_ACCESS_KEY_ID'
|
33
|
+
Geokit::Geocoders::AwsGeospacesGeocoder.secret_access_key = 'YOUR_SECRET_ACCESS_KEY'
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# use :aws_geospaces to specify this geocoder in your list of geocoders.
|
41
|
+
Geokit::Geocoders::AwsGeospacesGeocoder.geocode("Sunnyvale, CA")
|
42
|
+
```
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it ( https://github.com/adamtao/geokit_aws_geospaces/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "geokit_aws_geoplaces"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Adam Anderson"]
|
9
|
+
spec.email = ["adam@makeascene.com"]
|
10
|
+
spec.summary = %q{Geokit custom geocoder for AWS GeoPlaces service}
|
11
|
+
spec.description = %q{Geokit custom geocoder for AWS GeoPlaces service}
|
12
|
+
spec.homepage = "https://github.com/adamtao/geokit_aws_geoplaces.git"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
|
23
|
+
spec.add_dependency "geokit"
|
24
|
+
spec.add_dependency "aws-sdk-geoplaces"
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'aws-sdk-geoplaces'
|
2
|
+
require 'geokit'
|
3
|
+
|
4
|
+
module Geokit
|
5
|
+
module Geocoders
|
6
|
+
|
7
|
+
# and use :aws_geoplaces to specify this geocoder in your list of geocoders.
|
8
|
+
class AwsGeoplacesGeocoder < Geocoder
|
9
|
+
|
10
|
+
# Use via:
|
11
|
+
# Geokit::Geocoders::AwsGeoplacesGeocoder.region = "<your aws region>"
|
12
|
+
# Geokit::Geocoders::AwsGeoplacesGeocoder.access_key_id = "<your key>"
|
13
|
+
# Geokit::Geocoders::AwsGeoplacesGeocoder.secret_access_key = "<your secret>"
|
14
|
+
config :region, :access_key_id, :secret_access_key
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.do_geocode(address, options = {})
|
19
|
+
client = Aws::GeoPlaces::Client.new(
|
20
|
+
region: region,
|
21
|
+
credentials: Aws::Credentials.new( access_key_id, secret_access_key )
|
22
|
+
)
|
23
|
+
res = client.geocode(query_text: address)
|
24
|
+
return GeoLoc.new unless res.successful?
|
25
|
+
|
26
|
+
parse_response res
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.parse_response(res)
|
30
|
+
return GeoLoc.new unless res.result_items.size > 0
|
31
|
+
result_item = res.result_items.first
|
32
|
+
|
33
|
+
extract_geoloc result_item
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.extract_geoloc(result_item)
|
37
|
+
loc = new_loc
|
38
|
+
loc.lat = result_item.position[1]
|
39
|
+
loc.lng = result_item.position[0]
|
40
|
+
|
41
|
+
set_address_components(result_item, loc)
|
42
|
+
set_precision(result_item, loc)
|
43
|
+
set_bounds(result_item, loc)
|
44
|
+
|
45
|
+
loc.success = true
|
46
|
+
loc
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.set_address_components(result_item, loc)
|
50
|
+
address = result_item.address
|
51
|
+
|
52
|
+
loc.country = address.country.name
|
53
|
+
loc.country_code = address.country.code_2
|
54
|
+
loc.city = address.locality
|
55
|
+
loc.district = address.district
|
56
|
+
loc.zip = address.postal_code
|
57
|
+
|
58
|
+
if address.region.present?
|
59
|
+
loc.state_code = address.region.code
|
60
|
+
loc.state_name = address.region.name
|
61
|
+
loc.state = address.region.name
|
62
|
+
end
|
63
|
+
|
64
|
+
if address.sub_region.present?
|
65
|
+
loc.county = address.sub_region.name
|
66
|
+
end
|
67
|
+
|
68
|
+
if result_item.place_type.to_s == "PointAddress"
|
69
|
+
loc.street_address = "#{address.address_number} #{address.street}"
|
70
|
+
loc.street_name = address.street
|
71
|
+
loc.street_number = address.address_number
|
72
|
+
loc.full_address = address.label
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
PRECISION_MAP = {
|
77
|
+
"PointAddress" => "address",
|
78
|
+
"Street" => "street",
|
79
|
+
"Locality" => "city",
|
80
|
+
"PostalCode" => "zip",
|
81
|
+
"Region" => "state",
|
82
|
+
"Country" => "country"
|
83
|
+
}
|
84
|
+
|
85
|
+
def self.set_precision(result_item, loc)
|
86
|
+
loc.precision = PRECISION_MAP[result_item.place_type] || 'unknown'
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.set_bounds(result_item, loc)
|
90
|
+
map_view = result_item.map_view
|
91
|
+
|
92
|
+
loc.suggested_bounds = Bounds.normalize(
|
93
|
+
[ map_view[1], map_view[0] ],
|
94
|
+
[ map_view[3], map_view[2] ]
|
95
|
+
)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geokit_aws_geoplaces
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Anderson
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-07-10 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: bundler
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :development
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: geokit
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: aws-sdk-geoplaces
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
description: Geokit custom geocoder for AWS GeoPlaces service
|
69
|
+
email:
|
70
|
+
- adam@makeascene.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- ".gitignore"
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
78
|
+
- README.md
|
79
|
+
- geokit_aws_geoplaces.gemspec
|
80
|
+
- lib/geokit_aws_geoplaces.rb
|
81
|
+
homepage: https://github.com/adamtao/geokit_aws_geoplaces.git
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubygems_version: 3.6.2
|
100
|
+
specification_version: 4
|
101
|
+
summary: Geokit custom geocoder for AWS GeoPlaces service
|
102
|
+
test_files: []
|