Skip to content

Commit a6d3278

Browse files
committed
Fix issue matching locations to positions
This fixes an issue where locations don't match as we're using the wrong projection to fetch latitude and longitude values. Jira-Issue: MAV-6707 Jira-Issue: MAV-6379
1 parent 0d0727f commit a6d3278

4 files changed

Lines changed: 32 additions & 10 deletions

File tree

app/lib/location_position_updater.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def self.call(...) = new(...).call
2828

2929
private
3030

31-
def full_address = location.address_parts.join(", ")
31+
def query = [location.name, location.address_parts].join(", ")
3232

3333
def position
34-
response = OrdnanceSurvey::PlacesAPI.find(full_address)
34+
response = OrdnanceSurvey::PlacesAPI.find(query)
3535

3636
results = response[:results]
3737
raise NoResults if results.blank?

app/lib/ordnance_survey/places_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def initialize
99
@base_url = "https://api.os.uk"
1010
end
1111

12-
def find(query)
13-
params = { query:, format: "json" }
12+
def find(query, max_results: 1, output_srs: "EPSG:4326")
13+
params = { query:, maxresults: max_results, output_srs:, format: "json" }
1414
response = connection.get("/search/places/v1/find", params)
1515
response.body.deep_transform_keys(&:downcase).deep_symbolize_keys
1616
end

spec/lib/location_position_updater_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
let(:location) do
88
create(
99
:community_clinic,
10+
name: "Westminster Clinic",
1011
address_line_1: "1 High Street",
1112
address_town: "London",
1213
address_postcode: "SW1A 1AA",
@@ -49,7 +50,7 @@
4950

5051
it "calls the API with the address" do
5152
expect(OrdnanceSurvey::PlacesAPI).to receive(:find).with(
52-
"1 High Street, London, SW1A 1AA"
53+
"Westminster Clinic, 1 High Street, London, SW1A 1AA"
5354
)
5455
call
5556
end
@@ -93,6 +94,7 @@
9394
let(:location) do
9495
create(
9596
:community_clinic,
97+
name: "Westminster Clinic",
9698
address_line_1: "1 High Street",
9799
address_town: nil,
98100
address_postcode: "SW1A 1AA",
@@ -115,7 +117,7 @@
115117

116118
it "calls the API with partial address" do
117119
expect(OrdnanceSurvey::PlacesAPI).to receive(:find).with(
118-
"1 High Street, SW1A 1AA"
120+
"Westminster Clinic, 1 High Street, SW1A 1AA"
119121
)
120122
call
121123
end

spec/lib/ordnance_survey/places_api_spec.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@
7272

7373
before do
7474
stub_request(:get, "#{api_url}/search/places/v1/find").with(
75-
query: hash_including(query:, format: "json"),
75+
query: {
76+
query:,
77+
format: "json",
78+
maxresults: 1,
79+
output_srs: "EPSG:4326"
80+
},
7681
headers: {
7782
"Key" => api_key
7883
}
@@ -103,7 +108,12 @@
103108
context "when the request is invalid" do
104109
before do
105110
stub_request(:get, "#{api_url}/search/places/v1/find").with(
106-
query: hash_including(query:, format: "json"),
111+
query: {
112+
query:,
113+
format: "json",
114+
maxresults: 1,
115+
output_srs: "EPSG:4326"
116+
},
107117
headers: {
108118
"Key" => api_key
109119
}
@@ -123,7 +133,12 @@
123133
context "when rate limit is exceeded" do
124134
before do
125135
stub_request(:get, "#{api_url}/search/places/v1/find").with(
126-
query: hash_including(query:, format: "json"),
136+
query: {
137+
query:,
138+
format: "json",
139+
maxresults: 1,
140+
output_srs: "EPSG:4326"
141+
},
127142
headers: {
128143
"Key" => api_key
129144
}
@@ -138,7 +153,12 @@
138153
context "when there is an unexpected error" do
139154
before do
140155
stub_request(:get, "#{api_url}/search/places/v1/find").with(
141-
query: hash_including(query:, format: "json"),
156+
query: {
157+
query:,
158+
format: "json",
159+
maxresults: 1,
160+
output_srs: "EPSG:4326"
161+
},
142162
headers: {
143163
"Key" => api_key
144164
}

0 commit comments

Comments
 (0)