Created
February 12, 2011 00:25
-
-
Save jonobr1/823332 to your computer and use it in GitHub Desktop.
Lat / Lon point's to X / Y algorithm's in actionscript, but easily portable
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 function getPoint(lat : Number, lon : Number, mapwidth : uint, mapheight : uint) : Point | |
{ | |
return new Point(((lon+180) / 360) * mapwidth, ((90-lat) / 180) * mapheight); | |
} | |
private function getMercatorPoint(lat : Number, lon : Number, mapwidth : uint, mapheight : uint) : Point | |
{ | |
return new Point(((lon+180) / 360) * mapwidth, ((90-GudermannianInv(lat)) / 180) * mapheight); | |
} | |
private function GudermannianInv(lat : Number) : Number | |
{ | |
var sign : Number = Math.sin(lat) > 0 ? 1 : -1; | |
var sin : Number = Math.sin(lat * 0.0174532925 * sign); | |
return sign * (Math.log((1 + sin) / (1 - sin)) / 2) * 28.6478898; | |
} |
:) Many TY's for the help Ricardo!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recognise this ;)