문제

WGS84 좌표계의 점을 Google 지도의 지도 위치(픽셀 위치)로 변환하고 확대/축소 수준도 지원하는 일부 샘플 코드를 검색합니다.

코드에 주석이 잘 달려 있다면 다른 언어로 되어 있을 수도 있습니다.

오픈 소스 Java 프로젝트를 알려줄 수도 있습니다. :)

발견된 일부 리소스:

오픈레이어 구현.

JOSM 프로젝트

훌륭한 자바 지도 투영 라이브러리 JH LABS에서.이는 순수 Java PROJ.4 포트입니다.WGS84에서 미터로 투영을 수행합니다.여기에서 미터를 타일 픽셀로 변환하는 것은 매우 간단합니다.

도움이 되었습니까?

해결책

Java의 타일 유틸리티 코드 mapki.com(Google 지도 개발자를 위한 훌륭한 리소스)

다른 팁

JavaSCript의 함수는 다음과 같습니다.OpenLayers에서 추출됨

function toMercator (lon, lat) {
  var x = lon * 20037508.34 / 180;
  var y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
  y = y * 20037508.34 / 180;

  return [x, y];
  }

function inverseMercator (x, y) {
  var lon = (x / 20037508.34) * 180;
  var lat = (y / 20037508.34) * 180;

  lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);

  return [lon, lat];
  }

Java로 변환하는 것은 매우 간단합니다.

GeoTools 상상할 수 있는 모든 좌표계와 Google 지도 사이에서 변환하는 코드가 있습니다.오픈소스이기도 합니다.그러나 GeoTools는 크기가 큰 도서관이므로 작고 빠르고 쉬운 것을 찾고 있다면 갈 길이 아닐 가능성이 높습니다.

다른 GIS/좌표 변환 등을 수행하려는 경우에는 이 방법을 적극 권장합니다.또한.

GeoTools 또는 이와 유사한 것을 사용하는 경우 Google 지도 좌표계가 EPSG 3785라는 것을 알고 싶을 수도 있습니다.

나는 이것을 PHP로 포팅했습니다. 누군가 필요하다면 다음과 같은 코드가 있습니다.

메르카토르에게:

$lon = ($lon * 20037508.34) / 180;
$lat = log(tan((90 + $lat) * M_PI / 360)) / (M_PI / 180);
$lat = $lat * 20037508.34 / 180;

메르카토르에서:

$lon = ($lon / 20037508.34) * 180;
$lat = ($lat / 20037508.34) * 180;
$lat = 180/M_PI * (2 * atan(exp($lat * M_PI / 180)) - M_PI / 2);
/*
 * Utility functions to transform between wgs84 and google projection coordinates
 * Derived from openmap http://openmap.bbn.com/
 */

public class MercatorTransform {
    public final static double NORTH_POLE = 90.0;
    public final static double SOUTH_POLE = -NORTH_POLE;
    public final static double DATELINE = 180.0;
    public final static double LON_RANGE = 360.0;

    final public static transient double wgs84_earthEquatorialRadiusMeters_D = 6378137.0;
    private static double latfac = wgs84_earthEquatorialRadiusMeters_D;
    private static double lonfac = wgs84_earthEquatorialRadiusMeters_D;

    final public static transient double HALF_PI_D = Math.PI / 2.0d;

    /**
     * Returns google projection coordinates from wgs84 lat,long coordinates
     */
    public static double[] forward(double lat, double lon) {

        lat = normalizeLatitude(lat);
        lon = wrapLongitude(lon);

        double latrad = Math.toRadians(lat);
        double lonrad = Math.toRadians(lon);

        double lat_m = latfac * Math.log(Math.tan(((latrad + HALF_PI_D) / 2d)));
        double lon_m = lonfac * lonrad;

        double[] x = { lon_m, lat_m };
        return x;
    }

    /**
     * Returns wgs84 lat,long coordinates from google projection coordinates
     */
    public static float[] inverse(float lon_m, float lat_m) {
        double latrad = (2d * Math.atan(Math.exp(lat_m / latfac))) - HALF_PI_D;
        double lonrad = lon_m / lonfac;

        double lat = Math.toDegrees(latrad);
        double lon = Math.toDegrees(lonrad);

        lat = normalizeLatitude(lat);
        lon = wrapLongitude(lon);
        float[] x = { (float) lat, (float) lon };

        return x;
    }

    private static double wrapLongitude(double lon) {
        if ((lon < -DATELINE) || (lon > DATELINE)) {
            lon += DATELINE;
            lon = lon % LON_RANGE;
            lon = (lon < 0) ? DATELINE + lon : -DATELINE + lon;
        }
        return lon;
    }

    private static double normalizeLatitude(double lat) {
        if (lat > NORTH_POLE) {
            lat = NORTH_POLE;
        }
        if (lat < SOUTH_POLE) {
            lat = SOUTH_POLE;
        }
        return lat;
    }

}

누군가 Google 지도에서 자바스크립트 코드를 가져와 Python으로 이식했습니다. gmerc.py

나는 이것을 사용했고 훌륭하게 작동합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top