Open tobyprivett opened 2 years ago
A complete fix for this would need to take into account how the gem currently adjusts "short" easting and northing values by right-zero-padding them; see for example https://github.com/DEFRA/os-map-ref/blob/7bed0439d9442fd90a82c42ee49a8a55a6f6de57/spec/os_map_ref/input_processor_spec.rb#L78 That logic would need to be somehow reconciled with the need to left-zero-pad in some cases. Such a change could adversely impact current users of the gem. Taking this into account, it was decided to retain the current behaviour of the gem and to update the README to explain that some easting/northern values should be left-zero-padded on input.
The
Location
class is incorrectly caclulating themap_reference
.This problem arises because first character of the easting/northing is used to locate the grid key in a matrix, and expects inputs with a specific number of characters.
Starting with a postcode
TQ13 7LJ
, the EA Address Facade via defra-ruby-address gives useasting: 277938.47, northing: 70817.97
If we pass these values into the
OsMapRef::Location
class, the northing will be70817
. And this gives us an incorrect grid reference in Scotland:If we append a
0
to the northing , we get a grid reference in the right location:However, northing should be a number, and numbers don't have leading zeros. The OS Places API states that the
Y_COORDINATE
is a Float.Recommendation is to re-write the
Location
class using theetoString
method of this Javascript class as a starting point.