1

For example if coordinates are 17.12345678, -82.12345678, and I want to convert them to 3 decimal digits.

Expected result: 17.123, -82.123

Is there any API in OpenLayers 2 to truncate coordinates (LonLat) to decimal precision?

2
  • Your meaning is unclear. Do you really want to snap vertices to the nearest degree?
    – Vince
    Commented Dec 20, 2018 at 11:30
  • if coordinates are 17.12345678, -82.12345678, For eg. If I want to convert them to 3 decimal digits, Expected result: 17.123, -82.123 Is there any api in openLayers 2 to achieve this? Commented Dec 21, 2018 at 6:00

1 Answer 1

1

If you are referring to the LonLat object you could define your own method

OpenLayers.LonLat.prototype.truncate = function(digits) {
    var pow = Math.pow(10, digits);
    return new OpenLayers.LonLat(Math.round(this.lon * pow)/pow, Math.round(this.lat * pow)/pow);
}
1
  • Thanks! So I presume there is no built-in api in OpenLayers 2 Commented Dec 21, 2018 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.