The VEImagery service gives us the ability to render static versions of Virtual Earth Maps. As handy as this is it would also be handy to be able to georeference the image that is returned. The article found here:
explains how to convert from LatLong to Pixel so that custom icons could be added to the map, however the conversion from Pixel to LatLong was not needed at that time. Building on top of the code that was provided in that article the following method can be used to calculate a LatLong value based on the pixel coordinate of a static image. The following formula can be used to perform this calculation.
double Longitude = (((double)x * 360) / (256 * Math.Pow(2, view.zoom))) – 180;
double efactor = Math.Exp((0.5 – (double)y / 256 / Math.Pow(2, view.zoom)) * 4 * Math.PI);
double Latitude = Math.Asin((efactor – 1) / (efactor + 1)) * 180 / Math.PI;
LatLong latlong = new LatLong();
The complete source code can be downloaded here:
Here is a screen shot of this application in action.