Given:
an image of a map section that I cut from GOOGLE MAPS
coordinates of the 4 corners of the image (lat/long).
- leftTopLat = 47.536
- leftTopLon = 21.5203
- rightTopLat = 47.554
- rightTopLon = 21.5495
- leftBottomLat = 47.528437
- leftBottomLon = 21.530410
- rightBottomLat = 47.546455
- rightBottomLon = 21.559721
coordinates of a point to be displayed (targetLat/targetLon)
- targetLat = 47.541223
- targetLon = 21.53998275
The problem is that the map section is not parallel to the equator, it is rotated by 42 degrees, so the warmed-up code no longer works properly.
double leftTopLat = 47.535974;
double leftTopLon = 21.520250;
double rightTopLat = 47.553975;
double rightTopLon = 21.549528;
double leftBottomLat = 47.528437;
double leftBottomLon = 21.530410;
double rightBottomLat = 47.546455;
double rightBottomLon = 21.559721;
// center point
double targetLat = 47.54121025;
double targetLon = 21.53997725;
double mapWidth = 2518; // px
double mapHeight = 1060; // px
double xPercent = (targetLon - leftTopLon) / (rightTopLon - leftTopLon);
double yPercent = (targetLat - leftTopLat) / (leftBottomLat - leftTopLat);
System.out.println(xPercent); // 0.6738784246575766 but it should be around 0.5
System.out.println(yPercent); // -0.6889131297096822 but it should be around 0.5 or -0.5
float xOnScreen = (float) (xPercent * mapWidth);
float yOnScreen = (float) (yPercent * mapHeight) * (-1);
System.out.println(xOnScreen + " " + yOnScreen);
How can I solve it so that it works correctly?