I have a map of Israel.
I need to create a function that gets two double parameters (longitude and latitude) and that function should draw a small circle on that area in the map image.
I have the following info about the map:
- The width of the map in pixels
- The height of the map in pixels
- At-least one coordinate in latitude/longitude location on the map
- Distance in pixels between each degree
I need to convert the coordinates I get to pixel X, Y based on that image.
There's the following map image:
For example (Not an accurate example, it is just an example so you understand what I mean), the top-left coordinate is 33.5, 34 and the X, Y of it is 0,0 on the map.
How can I convert these coordinates to X, Y coordinates?
I tried this answer but it didn't really work, it shows me at 31.5, 34.5
instead of at 33, 34
.
UPDATE: here's a dummy quick code example of the other question;
public class MapRenderer extends JFrame {
public static void main(String... args) throws IOException {
new MapRenderer();
}
public MapRenderer() throws IOException {
setSize(new Dimension(614, 1141));
add(new TestPane());
setVisible(true);
}
}
class TestPane extends JPanel {
private BufferedImage image;
public TestPane() throws IOException {
File file = new File("israel_map.jpg");
BufferedImage image = ImageIO.read(file);
this.image = image;
}
@Override
public void paintComponent(Graphics g) {
double lon = 34;
double lat = 33;
int mapW = 614;
int mapH = 1141;
double x = (lon + 180) * (mapW / 360);
double latRad = lat * Math.PI / 180;
double mercN = Math.log( Math.tan( (Math.PI / 4) + (latRad / 2)) );
double y = (mapH / 2) - (mapW * mercN / (2 * Math.PI));
System.out.println("[lon: " + lon + " lat: " + lat + "]: X: " + x + " Y: " + y);
g.drawImage(image, 0, 0, null);
g.setColor(Color.RED);
g.drawOval((int) x, (int) y, 5, 5);
}
}
Output:
[lon: 34.0 lat: 33.0]: X: 214.0 Y: 510.3190109117399
screenshot: