Skip to content

Commit f58371f

Browse files
committed
Use correct coordinate system in GeocodeClientAdapter
When we were creating the coordinates in response to the Google location result we weren't specifying a coordinate system. This meant that the coordinates would use the default system (or no system, I'm not sure which) and when we came to compare them in the radius search with a coordinate in the Wgs84 coordinate system it would raise an exception. Updates to use the `NtsGeometryServices` factory to create the coordinate in the correct system.
1 parent 69752ab commit f58371f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

GetIntoTeachingApi/Adapters/GeocodeClientAdapter.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System.Linq;
22
using System.Threading.Tasks;
33
using GeocodeSharp.Google;
4+
using GetIntoTeachingApi.Database;
45
using GetIntoTeachingApi.Services;
56
using GetIntoTeachingApi.Utils;
67
using Microsoft.Extensions.Logging;
8+
using NetTopologySuite;
79
using NetTopologySuite.Geometries;
810

911
namespace GetIntoTeachingApi.Adapters
@@ -41,10 +43,12 @@ public async Task<Point> GeocodePostcodeAsync(string postcode)
4143
return null;
4244
}
4345

44-
_metrics.GoogleApiCalls.WithLabels(postcode, "success").Inc();
45-
46+
_metrics.GoogleApiCalls.WithLabels(postcode, "success").Inc();
47+
4648
var location = result.Geometry.Location;
47-
return new Point(new Coordinate(location.Longitude, location.Latitude));
49+
var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: DbConfiguration.Wgs84Srid);
50+
51+
return geometryFactory.CreatePoint(new Coordinate(location.Longitude, location.Latitude));
4852
}
4953
}
5054
}

0 commit comments

Comments
 (0)