Skip to content

Commit

Permalink
Use correct coordinate system in GeocodeClientAdapter
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ethax-ross committed Dec 2, 2020
1 parent 69752ab commit f58371f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions GetIntoTeachingApi/Adapters/GeocodeClientAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Linq;
using System.Threading.Tasks;
using GeocodeSharp.Google;
using GetIntoTeachingApi.Database;
using GetIntoTeachingApi.Services;
using GetIntoTeachingApi.Utils;
using Microsoft.Extensions.Logging;
using NetTopologySuite;
using NetTopologySuite.Geometries;

namespace GetIntoTeachingApi.Adapters
Expand Down Expand Up @@ -41,10 +43,12 @@ public async Task<Point> GeocodePostcodeAsync(string postcode)
return null;
}

_metrics.GoogleApiCalls.WithLabels(postcode, "success").Inc();

_metrics.GoogleApiCalls.WithLabels(postcode, "success").Inc();

var location = result.Geometry.Location;
return new Point(new Coordinate(location.Longitude, location.Latitude));
var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: DbConfiguration.Wgs84Srid);

return geometryFactory.CreatePoint(new Coordinate(location.Longitude, location.Latitude));
}
}
}

0 comments on commit f58371f

Please sign in to comment.