Skip to content

Commit 5300964

Browse files
committed
improve: restructured the coordinates return value
1 parent 77dc354 commit 5300964

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/geocoder/results/azure.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ def city
1515
end
1616

1717
def coordinates
18-
@data['position'] || {}
18+
if @data['position'].is_a?(String) # reverse geocoding result
19+
@data['position'].split(',').map(&:to_f)
20+
elsif @data['position'].is_a?(Hash) # forward geocoding result
21+
[@data['position']['lat'], @data['position']['lon']]
22+
end
1923
end
2024

2125
def country

test/unit/lookups/azure_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def test_azure_results_jakarta_properties
1919
def test_azure_results_jakarta_coordinates
2020
result = Geocoder.search('Jakarta').first
2121

22-
assert_equal -6.17476, result&.coordinates['lat']
23-
assert_equal 106.82707, result&.coordinates['lon']
22+
assert_equal -6.17476, result&.coordinates[0]
23+
assert_equal 106.82707, result&.coordinates[1]
2424
end
2525

2626
def test_azure_results_jakarta_viewport

0 commit comments

Comments
 (0)