I am using the Java based libraries of OpenGIS and JTS to convert coordinates from EPSG:3857 to EPSG:4326 to proceed to compute the distance using the Haversine formula. The distance features in a constraint on whether to zoom in further on a map or not.
We are using a tangible user interface and depend on the reactivity of the system. Unfortunately, the conversion is quite slow which induces even more delay than loading the map from a server. Would there be a less costly way to proceed with the conversion using local resources?
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326"); CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:3857"); MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, false); GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 3857); Point minPoint = geometryFactory.createPoint(new Coordinate(xMin, yMin)); Point minTargetPoint = (Point) JTS.transform(minPoint, transform); Point maxPoint = geometryFactory.createPoint(new Coordinate(xMax, yMax)); PointmaxTargetPoint = (Point) JTS.transform(maxPoint, transform);