Skip to content

Instantly share code, notes, and snippets.

@jonobr1
Created February 12, 2011 00:25
Show Gist options
  • Save jonobr1/823332 to your computer and use it in GitHub Desktop.
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
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;
}
@mrdoob
Copy link

mrdoob commented Aug 29, 2011

I recognise this ;)

@jonobr1
Copy link
Author

jonobr1 commented Aug 30, 2011

:) 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