Skip to content

Commit

Permalink
improve: restructured the coordinates return value
Browse files Browse the repository at this point in the history
  • Loading branch information
AhlOct committed Dec 2, 2024
1 parent 77dc354 commit 5300964
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/geocoder/results/azure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/unit/lookups/azure_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5300964

Please sign in to comment.