From 118ae86baae3187a3c7072ca776f4e9acfea7ca0 Mon Sep 17 00:00:00 2001 From: Ahluzain Octuviadi Date: Mon, 11 Nov 2024 07:40:02 +0700 Subject: [PATCH 01/10] Add lookup and result for Azure --- lib/geocoder/configuration.rb | 3 +- lib/geocoder/lookup.rb | 2 ++ lib/geocoder/lookups/azure.rb | 46 ++++++++++++++++++++++++++ lib/geocoder/results/azure.rb | 61 +++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 lib/geocoder/lookups/azure.rb create mode 100644 lib/geocoder/results/azure.rb diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb index d352200b3..616dd379a 100644 --- a/lib/geocoder/configuration.rb +++ b/lib/geocoder/configuration.rb @@ -68,7 +68,8 @@ class Configuration :basic_auth, :logger, :kernel_logger_level, - :cache_options + :cache_options, + :limit ] attr_accessor :data diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 87523cae8..3afff79cd 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -32,6 +32,7 @@ def all_services_with_http_requests def street_services @street_services ||= [ :location_iq, + :azure, :esri, :google, :google_premier, @@ -78,6 +79,7 @@ def ip_services @ip_services ||= [ :baidu_ip, :abstract_api, + :azure, :freegeoip, :geoip2, :maxmind, diff --git a/lib/geocoder/lookups/azure.rb b/lib/geocoder/lookups/azure.rb new file mode 100644 index 000000000..218e96573 --- /dev/null +++ b/lib/geocoder/lookups/azure.rb @@ -0,0 +1,46 @@ +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' + url = if query.reverse_geocode? + "#{protocol}://#{host}/reverse/json" + else + "#{protocol}://#{host}/json" + end + params = "?subscription-key=#{configuration.api_key}&api-version=1.0&query=#{query.sanitized_text}&limit=#{configuration.limit}" + + url + params + 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 \ No newline at end of file diff --git a/lib/geocoder/results/azure.rb b/lib/geocoder/results/azure.rb new file mode 100644 index 000000000..3bdd4c69f --- /dev/null +++ b/lib/geocoder/results/azure.rb @@ -0,0 +1,61 @@ +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 + @data['position'] || {} + 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 \ No newline at end of file From 3fda4ffe06e10f8e42b73c9dab509e4afdae93e2 Mon Sep 17 00:00:00 2001 From: Ahluzain Octuviadi Date: Mon, 11 Nov 2024 08:28:41 +0700 Subject: [PATCH 02/10] Add tests for Azure --- test/fixtures/azure_invalid_key | 8 +++ test/fixtures/azure_jakarta | 57 ++++++++++++++++ test/fixtures/azure_no_result | 12 ++++ test/fixtures/azure_reverse | 36 ++++++++++ test/unit/lookups/azure_test.rb | 114 ++++++++++++++++++++++++++++++++ 5 files changed, 227 insertions(+) create mode 100644 test/fixtures/azure_invalid_key create mode 100644 test/fixtures/azure_jakarta create mode 100644 test/fixtures/azure_no_result create mode 100644 test/fixtures/azure_reverse create mode 100644 test/unit/lookups/azure_test.rb diff --git a/test/fixtures/azure_invalid_key b/test/fixtures/azure_invalid_key new file mode 100644 index 000000000..799d12b7e --- /dev/null +++ b/test/fixtures/azure_invalid_key @@ -0,0 +1,8 @@ +{ + "error": { + "code": "InvalidKey", + "message": "The provided key was incorrect or the account resource does not exist.", + "target": "WWW-Authenticate", + "details": [] + } +} \ No newline at end of file diff --git a/test/fixtures/azure_jakarta b/test/fixtures/azure_jakarta new file mode 100644 index 000000000..a6b96e2ca --- /dev/null +++ b/test/fixtures/azure_jakarta @@ -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" + } + } + } + ] +} \ No newline at end of file diff --git a/test/fixtures/azure_no_result b/test/fixtures/azure_no_result new file mode 100644 index 000000000..0553ba9a7 --- /dev/null +++ b/test/fixtures/azure_no_result @@ -0,0 +1,12 @@ +{ + "summary": { + "query": "Jakarta", + "queryType": "NON_NEAR", + "queryTime": 66, + "numResults": 0, + "offset": 0, + "totalResults": 0, + "fuzzyLevel": 1 + }, + "results": [] +} \ No newline at end of file diff --git a/test/fixtures/azure_reverse b/test/fixtures/azure_reverse new file mode 100644 index 000000000..b2b47014d --- /dev/null +++ b/test/fixtures/azure_reverse @@ -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" + } + ] +} diff --git a/test/unit/lookups/azure_test.rb b/test/unit/lookups/azure_test.rb new file mode 100644 index 000000000..a10011697 --- /dev/null +++ b/test/unit/lookups/azure_test.rb @@ -0,0 +1,114 @@ +require 'test_helper' + +class AzureTest < GeocoderTestCase + + def setup + super + Geocoder.configure(lookup: :azure, limit: 1) + set_api_key!(:azure) + end + + def test_azure_results_jakarta_properties + result = Geocoder.search('Jakarta').first + + assert_equal 'Jakarta', result&.city + assert_equal 'Indonesia', result&.country + assert_equal 'Jakarta, Jakarta', result&.address + end + + def test_azure_results_jakarta_coordinates + result = Geocoder.search('Jakarta').first + + assert_equal -6.17476, result&.coordinates['lat'] + assert_equal 106.82707, result&.coordinates['lon'] + end + + def test_azure_results_jakarta_viewport + result = Geocoder.search('Jakarta').first + + assert_equal( + { + 'topLeftPoint' => { + 'lat' => -5.95462, + 'lon' => 106.68588 + }, + 'btmRightPoint'=> { + 'lat' => -6.37083, + 'lon' => 106.9729 + } + }, result&.viewport + ) + end + + def test_azure_reverse_results_properties + result = Geocoder.search([-6.198967624433219, 106.82358133258361]).first + + assert_equal 'Jakarta', result&.city + assert_equal 'Indonesia', result&.country + assert_equal 'Jalan Mohammad Husni Thamrin 10, Kecamatan Jakarta, DKI Jakarta 10230', result&.address + end + + def test_azure_no_result + result = Geocoder.search('no result') + + assert_equal 0, result&.length + end + + def test_azure_results_no_street_number + result = Geocoder.search('Jakarta').first + + assert_equal nil, result&.street_number + end + + def test_query_url + query = Geocoder::Query.new('Jakarta') + + assert_equal 'https://atlas.microsoft.com/search/address/json?subscription-key=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&api-version=1.0&query=Jakarta&limit=1', query.url + end + + def test_reverse_query_url + query = Geocoder::Query.new([-6.198967624433219, 106.82358133258361]) + + assert_equal "https://atlas.microsoft.com/search/address/reverse/json?subscription-key=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&api-version=1.0&query=-6.198967624433219,106.82358133258361&limit=1", query.url + end + + def test_azure_query_url_contains_api_key + lookup = Geocoder::Lookup::Azure.new + url = lookup.query_url( + Geocoder::Query.new( + 'Test Query' + ) + ) + + assert_match(/subscription-key=a+/, url) + end + + def test_azure_query_url_contains_text + lookup = Geocoder::Lookup::Azure.new + url = lookup.query_url( + Geocoder::Query.new( + 'PT Kulkul Teknologi Internasional' + ) + ) + + assert_match(/PT Kulkul Teknologi Internasional/i, url) + end + + def test_azure_reverse_query_url_contains_lat_lon + lookup = Geocoder::Lookup::Azure.new + url = lookup.query_url( + Geocoder::Query.new( + [-6.198967624433219, 106.82358133258361] + ) + ) + + assert_match(/query=-6\.198967624433219,106\.82358133258361/, url) + end + + def test_azure_invalid_key + result = Geocoder.search('invalid key').first + + assert_equal 'InvalidKey', result&.data&.last['code'] + assert_equal 'The provided key was incorrect or the account resource does not exist.', result&.data&.last['message'] + end +end \ No newline at end of file From 77d3dd9519fd69de60937c8547bb10a867c35fdf Mon Sep 17 00:00:00 2001 From: Ahluzain Octuviadi Date: Mon, 11 Nov 2024 10:30:23 +0700 Subject: [PATCH 03/10] Add API guide documentation for Geoapify --- README_API_GUIDE.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 58a103052..4f00879e8 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -61,6 +61,19 @@ Global Street Address Lookups ``` * Via environment variables and other external methods. See **Setting AWS Credentials** in the [AWS SDK for Ruby Developer Guide](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html). +### Azure (`:azure`) + +* **API key**: required (set `Geocoder.configure(lookup: :azure, api_key: "your_api_key", limit: your_limit)`) +* **Key signup**: https://azure.microsoft.com/en-us/products/azure-maps +* **Quota**: 5,000 request/month with free API key, more with paid keys (see https://azure.microsoft.com/en-us/pricing/details/azure-maps) +* **Region**: world +* **SSL support**: yes +* **Languages**: see https://learn.microsoft.com/en-us/azure/azure-maps/supported-languages +* **Documentation**: https://learn.microsoft.com/en-us/azure/azure-maps +* **Terms of Service**: https://azure.microsoft.com/en-us/support/legal +* **Limitations**: Azure Maps doesn't have any maximum daily limits on the number of requests that can be made, however there are limits to the maximum number of queries per second (QPS) (see https://learn.microsoft.com/en-us/azure/azure-maps/azure-maps-qps-rate-limits) +* **Notes**: To use Azure, set `Geocoder.configure(lookup: :azure, api_key: "your_api_key", limit: your_limit)` :limit - restrict the maximum amount of returned results, e.g. limit: 10. + ### Bing (`:bing`) * **API key**: required (set `Geocoder.configure(lookup: :bing, api_key: key)`) From fe7a1317da48cdbccba06f9e03bf866845240cd1 Mon Sep 17 00:00:00 2001 From: Ahluzain Octuviadi Date: Mon, 11 Nov 2024 11:11:04 +0700 Subject: [PATCH 04/10] Add support languages to query --- lib/geocoder/lookups/azure.rb | 28 +++++++++++++++++++--------- test/unit/lookups/azure_test.rb | 20 ++++++++++++++++---- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/geocoder/lookups/azure.rb b/lib/geocoder/lookups/azure.rb index 218e96573..a404d25fb 100644 --- a/lib/geocoder/lookups/azure.rb +++ b/lib/geocoder/lookups/azure.rb @@ -18,15 +18,25 @@ def supported_protocols private def base_query_url(query) - host = 'atlas.microsoft.com/search/address' - url = if query.reverse_geocode? - "#{protocol}://#{host}/reverse/json" - else - "#{protocol}://#{host}/json" - end - params = "?subscription-key=#{configuration.api_key}&api-version=1.0&query=#{query.sanitized_text}&limit=#{configuration.limit}" - - url + params + 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) diff --git a/test/unit/lookups/azure_test.rb b/test/unit/lookups/azure_test.rb index a10011697..ee244a8c8 100644 --- a/test/unit/lookups/azure_test.rb +++ b/test/unit/lookups/azure_test.rb @@ -63,13 +63,13 @@ def test_azure_results_no_street_number def test_query_url query = Geocoder::Query.new('Jakarta') - assert_equal 'https://atlas.microsoft.com/search/address/json?subscription-key=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&api-version=1.0&query=Jakarta&limit=1', query.url + assert_equal 'https://atlas.microsoft.com/search/address/json?api-version=1.0&language=en&limit=1&query=Jakarta&subscription-key=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', query.url end def test_reverse_query_url query = Geocoder::Query.new([-6.198967624433219, 106.82358133258361]) - assert_equal "https://atlas.microsoft.com/search/address/reverse/json?subscription-key=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&api-version=1.0&query=-6.198967624433219,106.82358133258361&limit=1", query.url + assert_equal "https://atlas.microsoft.com/search/address/reverse/json?api-version=1.0&language=en&limit=1&query=-6.198967624433219%2C106.82358133258361&subscription-key=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", query.url end def test_azure_query_url_contains_api_key @@ -83,6 +83,18 @@ def test_azure_query_url_contains_api_key assert_match(/subscription-key=a+/, url) end + def test_azure_query_url_contains_language + lookup = Geocoder::Lookup::Azure.new + url = lookup.query_url( + Geocoder::Query.new( + 'Test Query', + language: 'en' + ) + ) + + assert_match(/language=en/, url) + end + def test_azure_query_url_contains_text lookup = Geocoder::Lookup::Azure.new url = lookup.query_url( @@ -91,7 +103,7 @@ def test_azure_query_url_contains_text ) ) - assert_match(/PT Kulkul Teknologi Internasional/i, url) + assert_match(/PT\+Kulkul\+Teknologi\+Internasional/i, url) end def test_azure_reverse_query_url_contains_lat_lon @@ -102,7 +114,7 @@ def test_azure_reverse_query_url_contains_lat_lon ) ) - assert_match(/query=-6\.198967624433219,106\.82358133258361/, url) + assert_match(/query=-6\.198967624433219%2C106\.82358133258361/, url) end def test_azure_invalid_key From 24db6ce7c21c8745bf9eb9685f3e59303aab988f Mon Sep 17 00:00:00 2001 From: Ahluzain Octuviadi <44269739+AhlOct@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:04:26 +0700 Subject: [PATCH 05/10] remove :limit in configuration.rb --- lib/geocoder/configuration.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb index 616dd379a..d352200b3 100644 --- a/lib/geocoder/configuration.rb +++ b/lib/geocoder/configuration.rb @@ -68,8 +68,7 @@ class Configuration :basic_auth, :logger, :kernel_logger_level, - :cache_options, - :limit + :cache_options ] attr_accessor :data From 01245a66ffa16b33dc1c2feb40a5af3874e2766f Mon Sep 17 00:00:00 2001 From: Ahluzain Octuviadi Date: Mon, 2 Dec 2024 10:20:49 +0700 Subject: [PATCH 06/10] fix: add fixtures azure_madison_square_garden & fix lookup azure does not return empty array when no results. --- test/fixtures/azure_madison_square_garden | 50 +++++++++++++++++++ .../{azure_no_result => azure_no_results} | 0 test/unit/lookups/azure_test.rb | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/azure_madison_square_garden rename test/fixtures/{azure_no_result => azure_no_results} (100%) diff --git a/test/fixtures/azure_madison_square_garden b/test/fixtures/azure_madison_square_garden new file mode 100644 index 000000000..39e44cf97 --- /dev/null +++ b/test/fixtures/azure_madison_square_garden @@ -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 + } + } + } + ] +} diff --git a/test/fixtures/azure_no_result b/test/fixtures/azure_no_results similarity index 100% rename from test/fixtures/azure_no_result rename to test/fixtures/azure_no_results diff --git a/test/unit/lookups/azure_test.rb b/test/unit/lookups/azure_test.rb index ee244a8c8..73870e657 100644 --- a/test/unit/lookups/azure_test.rb +++ b/test/unit/lookups/azure_test.rb @@ -49,7 +49,7 @@ def test_azure_reverse_results_properties end def test_azure_no_result - result = Geocoder.search('no result') + result = Geocoder.search('no results') assert_equal 0, result&.length end From 4186dae0caed54587184836eb86dd36966135db9 Mon Sep 17 00:00:00 2001 From: Ahluzain Octuviadi Date: Mon, 2 Dec 2024 10:23:13 +0700 Subject: [PATCH 07/10] fix: undefined method limit & remove ! from params.merge!(super) --- lib/geocoder/lookups/azure.rb | 4 ++-- test/unit/lookups/azure_test.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/geocoder/lookups/azure.rb b/lib/geocoder/lookups/azure.rb index a404d25fb..2021b6dac 100644 --- a/lib/geocoder/lookups/azure.rb +++ b/lib/geocoder/lookups/azure.rb @@ -31,12 +31,12 @@ def query_url_params(query) params = { 'api-version' => 1.0, 'language' => query.options[:language] || 'en', - 'limit' => configuration.limit || 10, + 'limit' => configuration[:limit] || 10, 'query' => query.sanitized_text, 'subscription-key' => configuration.api_key } - params.merge!(super) + params.merge(super) end def results(query) diff --git a/test/unit/lookups/azure_test.rb b/test/unit/lookups/azure_test.rb index 73870e657..bb93b3273 100644 --- a/test/unit/lookups/azure_test.rb +++ b/test/unit/lookups/azure_test.rb @@ -4,7 +4,7 @@ class AzureTest < GeocoderTestCase def setup super - Geocoder.configure(lookup: :azure, limit: 1) + Geocoder.configure(lookup: :azure, azure: { limit: 1 }) set_api_key!(:azure) end From 77dc354aeb321d74c23a7d03805bb6dbb84be7ec Mon Sep 17 00:00:00 2001 From: Ahluzain Octuviadi Date: Mon, 2 Dec 2024 10:23:56 +0700 Subject: [PATCH 08/10] improve: remove :azure from IP addresses --- lib/geocoder/lookup.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 3afff79cd..bef2f3494 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -79,7 +79,6 @@ def ip_services @ip_services ||= [ :baidu_ip, :abstract_api, - :azure, :freegeoip, :geoip2, :maxmind, From 5300964e0f257e9dbf4650427b48448f2f8d8ab4 Mon Sep 17 00:00:00 2001 From: Ahluzain Octuviadi Date: Mon, 2 Dec 2024 10:33:10 +0700 Subject: [PATCH 09/10] improve: restructured the coordinates return value --- lib/geocoder/results/azure.rb | 6 +++++- test/unit/lookups/azure_test.rb | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/geocoder/results/azure.rb b/lib/geocoder/results/azure.rb index 3bdd4c69f..5ea48c298 100644 --- a/lib/geocoder/results/azure.rb +++ b/lib/geocoder/results/azure.rb @@ -15,7 +15,11 @@ def city end def coordinates - @data['position'] || {} + 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 diff --git a/test/unit/lookups/azure_test.rb b/test/unit/lookups/azure_test.rb index bb93b3273..bac0a363a 100644 --- a/test/unit/lookups/azure_test.rb +++ b/test/unit/lookups/azure_test.rb @@ -19,8 +19,8 @@ def test_azure_results_jakarta_properties def test_azure_results_jakarta_coordinates result = Geocoder.search('Jakarta').first - assert_equal -6.17476, result&.coordinates['lat'] - assert_equal 106.82707, result&.coordinates['lon'] + assert_equal -6.17476, result&.coordinates[0] + assert_equal 106.82707, result&.coordinates[1] end def test_azure_results_jakarta_viewport From bee09bf89158608cb5b46e2e1121223c74b0479e Mon Sep 17 00:00:00 2001 From: Ahluzain Octuviadi Date: Wed, 4 Dec 2024 05:02:26 +0700 Subject: [PATCH 10/10] Update README_API_GUIDE.md --- README_API_GUIDE.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 4f00879e8..b9241c11e 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -63,7 +63,6 @@ Global Street Address Lookups ### Azure (`:azure`) -* **API key**: required (set `Geocoder.configure(lookup: :azure, api_key: "your_api_key", limit: your_limit)`) * **Key signup**: https://azure.microsoft.com/en-us/products/azure-maps * **Quota**: 5,000 request/month with free API key, more with paid keys (see https://azure.microsoft.com/en-us/pricing/details/azure-maps) * **Region**: world @@ -72,7 +71,7 @@ Global Street Address Lookups * **Documentation**: https://learn.microsoft.com/en-us/azure/azure-maps * **Terms of Service**: https://azure.microsoft.com/en-us/support/legal * **Limitations**: Azure Maps doesn't have any maximum daily limits on the number of requests that can be made, however there are limits to the maximum number of queries per second (QPS) (see https://learn.microsoft.com/en-us/azure/azure-maps/azure-maps-qps-rate-limits) -* **Notes**: To use Azure, set `Geocoder.configure(lookup: :azure, api_key: "your_api_key", limit: your_limit)` :limit - restrict the maximum amount of returned results, e.g. limit: 10. +* **Notes**: To use Azure, set `Geocoder.configure(lookup: :azure, api_key: "your_api_key", azure: { limit: your_limit })` limit is optional - limit the maximum number of results returned, default 10. ### Bing (`:bing`)