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

Feature/azure maps #1667

Merged
merged 10 commits into from
Dec 4, 2024
Merged

Conversation

AhlOct
Copy link
Contributor

@AhlOct AhlOct commented Nov 11, 2024

  • Lookups
  • Results
  • Tests
  • Documentation

@alexreisner
Copy link
Owner

Thanks for this. It looks great. Just one thing: there's no need to add the :limit option in configuration.rb. It should work fine without that. If you can remove that, I believe it will fix the erroring test. Thanks!

@AhlOct AhlOct requested a review from empeje November 28, 2024 15:07
Copy link
Owner

@alexreisner alexreisner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, there were a few additional issues. In addition to what I've mentioned in comments:

  1. You need to add a result fixture called azure_madison_square_garden. This is expected by the tests that run on all lookups to make sure global result attributes are supported.
  2. After making all the recommended changes, you'll still see one failing test. The failure message is "Lookup azure does not return empty array when no results." Can you look into fixing that?

Thanks. And let me know if you have any questions about any comments.

params = {
'api-version' => 1.0,
'language' => query.options[:language] || 'en',
'limit' => configuration.limit || 10,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we need to use configuration[:limit] instead of configuration.limit, since :limit is not a global config option. (See my comment in test/unit/lookups/azure_test.rb for more info.)


def setup
super
Geocoder.configure(lookup: :azure, limit: 1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since :limit is Azure-specific (not a global config option), it needs to be set in a separate hash: Geocoder.configure(lookup: :azure, azure: {limit: 1})

end

def coordinates
@data['position'] || {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coordinates method must return a 2-element array with [lat,lon]. So we need something like this:

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

result = Geocoder.search('Jakarta').first

assert_equal -6.17476, result&.coordinates['lat']
assert_equal 106.82707, result&.coordinates['lon']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we've restructured the coordinates return value, this should be:

assert_equal -6.17476, result&.coordinates[0]
assert_equal 106.82707, result&.coordinates[1]

'subscription-key' => configuration.api_key
}

params.merge!(super)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, I would remove the ! from the method name, since params is discarded when the method exits (the in-place merging is irrelevant, we're just returning the result of the merge).

@@ -78,6 +79,7 @@ def ip_services
@ip_services ||= [
:baidu_ip,
:abstract_api,
:azure,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this line. :azure is for physical addresses, not IP addresses.

@AhlOct
Copy link
Contributor Author

AhlOct commented Dec 2, 2024

Thanks for your suggestions. I've fixed all issues you have mentioned and test 100% passed in my local. Now, I think we can run test again.

@alexreisner alexreisner self-requested a review December 2, 2024 18:02
Copy link
Owner

@alexreisner alexreisner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! Just one more thing, because I forgot to look at the README. Two minor changes there and then we're ready to merge.

@@ -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)`)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The info in parentheses is duplicated below. Let's remove it here.

* **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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  1. Let's fix the syntax, showing that :limit has to be specified in an azure: {...} hash.
  2. This makes it sound like :limit is required, which it isn't,, so let's specify the default (10) and mention that it's optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated README_API_GUIDE.md, sorry I forgot to update it yesterday.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, thanks!

@alexreisner alexreisner merged commit c1a19f2 into alexreisner:master Dec 4, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants