-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1667 from kulkultech/feature/azure-maps
Feature/azure maps
- Loading branch information
Showing
10 changed files
with
423 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'geocoder/lookups/base' | ||
require 'geocoder/results/azure' | ||
|
||
module Geocoder::Lookup | ||
class Azure < Base | ||
def name | ||
'Azure' | ||
end | ||
|
||
def required_api_key_parts | ||
['api_key'] | ||
end | ||
|
||
def supported_protocols | ||
[:https] | ||
end | ||
|
||
private | ||
|
||
def base_query_url(query) | ||
host = 'atlas.microsoft.com/search/address' | ||
|
||
if query.reverse_geocode? | ||
"#{protocol}://#{host}/reverse/json?" | ||
else | ||
"#{protocol}://#{host}/json?" | ||
end | ||
end | ||
|
||
def query_url_params(query) | ||
params = { | ||
'api-version' => 1.0, | ||
'language' => query.options[:language] || 'en', | ||
'limit' => configuration[:limit] || 10, | ||
'query' => query.sanitized_text, | ||
'subscription-key' => configuration.api_key | ||
} | ||
|
||
params.merge(super) | ||
end | ||
|
||
def results(query) | ||
return [] unless (doc = fetch_data(query)) | ||
|
||
return doc if doc['error'] | ||
|
||
if doc['results']&.any? | ||
doc['results'] | ||
elsif doc['addresses']&.any? | ||
doc['addresses'] | ||
else | ||
[] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'geocoder/results/base' | ||
|
||
module Geocoder::Result | ||
class Azure < Base | ||
def address | ||
@data['address']['freeformAddress'] | ||
end | ||
|
||
def building_number | ||
@data['address']['buildingNumber'] | ||
end | ||
|
||
def city | ||
@data['address']['municipality'] | ||
end | ||
|
||
def coordinates | ||
if @data['position'].is_a?(String) # reverse geocoding result | ||
@data['position'].split(',').map(&:to_f) | ||
elsif @data['position'].is_a?(Hash) # forward geocoding result | ||
[@data['position']['lat'], @data['position']['lon']] | ||
end | ||
end | ||
|
||
def country | ||
@data['address']['country'] | ||
end | ||
|
||
def country_code | ||
@data['address']['countryCode'] | ||
end | ||
|
||
def district | ||
@data['address']['municipalitySubdivision'] | ||
end | ||
|
||
def postal_code | ||
@data['address']['postalCode'] | ||
end | ||
|
||
def province | ||
@data['address']['countrySubdivision'] | ||
end | ||
|
||
def state | ||
@data['address']['countrySubdivision'] | ||
end | ||
|
||
def state_code | ||
@data['address']['countrySubdivisionCode'] | ||
end | ||
|
||
def street_name | ||
@data['address']['streetName'] | ||
end | ||
|
||
def street_number | ||
@data['address']['streetNumber'] | ||
end | ||
|
||
def viewport | ||
@data['viewport'] || {} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"error": { | ||
"code": "InvalidKey", | ||
"message": "The provided key was incorrect or the account resource does not exist.", | ||
"target": "WWW-Authenticate", | ||
"details": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"summary": { | ||
"query": "Jakarta", | ||
"queryType": "NON_NEAR", | ||
"queryTime": 66, | ||
"numResults": 1, | ||
"offset": 0, | ||
"totalResults": 10, | ||
"fuzzyLevel": 1 | ||
}, | ||
"results": [ | ||
{ | ||
"type": "Geography", | ||
"id": "6AhgONQ49YLQy9Ku_ocHcA", | ||
"score": 1, | ||
"entityType": "Municipality", | ||
"matchConfidence": { | ||
"score": 1 | ||
}, | ||
"address": { | ||
"municipality": "Jakarta", | ||
"countrySubdivision": "Jakarta", | ||
"countrySubdivisionName": "Jakarta", | ||
"countrySubdivisionCode": "JK", | ||
"countryCode": "ID", | ||
"country": "Indonesia", | ||
"countryCodeISO3": "IDN", | ||
"freeformAddress": "Jakarta, Jakarta" | ||
}, | ||
"position": { | ||
"lat": -6.17476, | ||
"lon": 106.82707 | ||
}, | ||
"viewport": { | ||
"topLeftPoint": { | ||
"lat": -5.95462, "lon": 106.68588 | ||
}, | ||
"btmRightPoint": { | ||
"lat": -6.37083, "lon": 106.9729 | ||
} | ||
}, | ||
"boundingBox": { | ||
"topLeftPoint": { | ||
"lat": -5.95462, "lon": 106.68588 | ||
}, | ||
"btmRightPoint": { | ||
"lat": -6.37083, "lon": 106.9729 | ||
} | ||
}, | ||
"dataSources": { | ||
"geometry": { | ||
"id": "00004944-3100-3c00-0000-000023c347ee" | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"summary": { | ||
"query": "madison square garden", | ||
"queryType": "NON_NEAR", | ||
"queryTime": 89, | ||
"numResults": 1, | ||
"offset": 0, | ||
"totalResults": 6, | ||
"fuzzyLevel": 1 | ||
}, | ||
"results": [ | ||
{ | ||
"type": "Street", | ||
"id": "QyS-HWGa0fkjABCOcS09Rw", | ||
"score": 0.8939382576343416, | ||
"matchConfidence": { | ||
"score": 0.8939382576343416 | ||
}, | ||
"address": { | ||
"streetName": "Garten Place", | ||
"municipality": "Madison Heights", | ||
"countrySecondarySubdivision": "Amherst", | ||
"countrySubdivision": "VA", | ||
"countrySubdivisionName": "Virginia", | ||
"countrySubdivisionCode": "VA", | ||
"postalCode": "24572", | ||
"extendedPostalCode": "24572-4418, 24572-4419", | ||
"countryCode": "US", | ||
"country": "United States", | ||
"countryCodeISO3": "USA", | ||
"freeformAddress": "Garten Place, Madison Heights, VA 24572", | ||
"localName": "Madison Heights" | ||
}, | ||
"position": { | ||
"lat": 37.484629, | ||
"lon": -79.109597 | ||
}, | ||
"viewport": { | ||
"topLeftPoint": { | ||
"lat": 37.485, | ||
"lon": -79.11055 | ||
}, | ||
"btmRightPoint": { | ||
"lat": 37.48439, | ||
"lon": -79.10872 | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"summary": { | ||
"query": "Jakarta", | ||
"queryType": "NON_NEAR", | ||
"queryTime": 66, | ||
"numResults": 0, | ||
"offset": 0, | ||
"totalResults": 0, | ||
"fuzzyLevel": 1 | ||
}, | ||
"results": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"summary": { | ||
"queryTime": 12, | ||
"numResults": 1 | ||
}, | ||
"addresses": [ | ||
{ | ||
"address": { | ||
"buildingNumber": "10", | ||
"streetNumber": "10", | ||
"routeNumbers": [], | ||
"street": "Jalan Mohammad Husni Thamrin", | ||
"streetName": "Jalan Mohammad Husni Thamrin", | ||
"streetNameAndNumber": "Jalan Mohammad Husni Thamrin 10", | ||
"countryCode": "ID", | ||
"countrySubdivision": "DKI Jakarta", | ||
"municipality": "Jakarta", | ||
"postalCode": "10230", | ||
"municipalitySecondarySubdivision": "Menteng", | ||
"country": "Indonesia", | ||
"countryCodeISO3": "IDN", | ||
"freeformAddress": "Jalan Mohammad Husni Thamrin 10, Kecamatan Jakarta, DKI Jakarta 10230", | ||
"boundingBox": { | ||
"northEast": "-6.198818,106.823264", | ||
"southWest": "-6.199555,106.823246", | ||
"entity": "position" | ||
}, | ||
"countrySubdivisionName": "DKI Jakarta", | ||
"countrySubdivisionCode": "JK", | ||
"localName": "Jakarta" | ||
}, | ||
"position": "-6.199203,106.823082", | ||
"id": "hlyQM4iHOYn16mWumCtnJA" | ||
} | ||
] | ||
} |
Oops, something went wrong.