Skip to content

Instantly share code, notes, and snippets.

@skyebook
Created July 20, 2012 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyebook/3152659 to your computer and use it in GitHub Desktop.
Save skyebook/3152659 to your computer and use it in GitHub Desktop.
Mercator Meters Per Pixel
public static final double EARTH_CIRCUMFERENCE = 637279.82;
public double getMetersPerPixelAt(LatLon latLon, int zoomLevel){
//S=C*cos(y)/2^(z+8)
double latCos = Math.cos(Math.toDegrees(latLon.getLat()));
System.out.println("latCos " + latCos);
double result = EARTH_CIRCUMFERENCE*latCos;
return result/Math.pow(2, zoomLevel+8);
}
@skyebook
Copy link
Author

This has a bug where the result is always negative

@skyebook
Copy link
Author

Converting the latitude from radians to degrees first fixes this

@skyebook
Copy link
Author

Nope, this isn't fixed... still a bug </3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment