相关疑难解决方法(0)

将经度/纬度转换为X/Y坐标

我使用Google Maps API创建了一张地图,突出了所有明尼苏达州的县.基本上,我使用一组经度/纬度坐标创建了县多边形.这是生成的地图的屏幕截图: -

在此输入图像描述

用户要求之一是能够将类似的地图作为图像,以便它们可以将其嵌入到PowerPoint /主题幻灯片中.我找不到任何有用的Google Maps API,它允许我按原样保存我的自定义地图(如果你知道一种方式,请告诉我),所以我想我应该用Java中的Graphics2D绘制它.

在阅读了将经度/纬度转换为X/Y坐标的公式后,我最终得到以下代码: -

private static final int    EARTH_RADIUS    = 6371;
private static final double FOCAL_LENGTH    = 500;

...

BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();

for (Coordinate coordinate : coordinates) {
    double latitude = Double.valueOf(coordinate.getLatitude());
    double longitude = Double.valueOf(coordinate.getLongitude());

    latitude = latitude * Math.PI / 180;
    longitude = longitude * Math.PI / 180;

    double x = EARTH_RADIUS * Math.sin(latitude) * Math.cos(longitude);
    double y = EARTH_RADIUS * Math.sin(latitude) * Math.sin(longitude); …
Run Code Online (Sandbox Code Playgroud)

java google-maps latitude-longitude cartesian coordinate-transformation

38
推荐指数
3
解决办法
5万
查看次数