Last active
April 19, 2020 04:53
-
-
Save rezaiyan/58be5d14a2409fdfac9b043364dca483 to your computer and use it in GitHub Desktop.
EPSG 4326 , EPSG 3857 converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static double EARTH_RADIUS = 6378137.0; | |
public static LatLng to4326(Wgs84 wgs84) { | |
double lat = Math.toDegrees(Math.atan(Math.exp(wgs84.getY() / EARTH_RADIUS)) * 2 - Math.PI/2); | |
double lng = Math.toDegrees(wgs84.getX() / EARTH_RADIUS); | |
return new LatLng(lat, lng); | |
} | |
public static Wgs84 toWgs84(LatLng latLng) { | |
double x = Math.toRadians(latLng.longitude) * EARTH_RADIUS; | |
double y = Math.log(Math.tan(Math.PI / 4 + Math.toRadians(latLng.latitude) / 2)) * EARTH_RADIUS; | |
return new Wgs84(x, y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment