SLH
Oct 26th, 2009, 08:08 AM
I have the following code which implements a formula:double xtile = (Coordinate.Long + 180) / 360 * (1 << ZoomLevel);
double ytile = (1 - Math.Log(Math.Tan(Coordinate.Lat * Math.PI / 180) + 1 / Math.Cos(Coordinate.Lat * Math.PI / 180)) / Math.PI) / 2 * (1 << ZoomLevel);
It converts map lat/long coordinates (degrees) into X/Y coordinates (on an image).
ZoomLevel is a constant.
I need to go the other way round i.e. from x,y coords on the image, to a lat,long coord on earth.
I'm thinking that to do this i just need to rearrange the formula(s?) in terms of coordinate.lat/long.
I'm ok with the X => Long conversion, but am having trouble rearranging the Y => Lat one.
Any help would be greatly appreciated.
double ytile = (1 - Math.Log(Math.Tan(Coordinate.Lat * Math.PI / 180) + 1 / Math.Cos(Coordinate.Lat * Math.PI / 180)) / Math.PI) / 2 * (1 << ZoomLevel);
It converts map lat/long coordinates (degrees) into X/Y coordinates (on an image).
ZoomLevel is a constant.
I need to go the other way round i.e. from x,y coords on the image, to a lat,long coord on earth.
I'm thinking that to do this i just need to rearrange the formula(s?) in terms of coordinate.lat/long.
I'm ok with the X => Long conversion, but am having trouble rearranging the Y => Lat one.
Any help would be greatly appreciated.