Asked by:
Coordinate conversion to latlong position

Plz Help me...........
How to convert mouse positions(X,Y) to LatLong. Plz give me formula or method.Tuesday, November 11, 2008 6:44 AM
General discussion
All replies

Get a GPS receiver and glue it to your mouse. You'll need a bigger mouse pad.Tuesday, November 11, 2008 6:32 PMModerator

Hi.
My problem is that How to convert my XY positions to latlong.
Basically my requirement is the formula or code,so plz help me in this direction.Wednesday, November 12, 2008 6:10 AM 
Dude you need to keep in mind what is required. First when you ask for lat and lon conversion from mouse coord. First...what is your picture scale with respect to the lon and lat on the picture or what ever you might be using to translate the mouse info to l/l. Than you use that information(scale) and the rest should be simple maths...but you have to figure out these things its just Maths!Friday, November 14, 2008 2:53 AM

hi, I have the same problem as well
I can easily convert my lat lon to a point I desired on the map by using this formula
http://msdn.microsoft.com/enus/library/bb259689.aspx
function MSLatLon2Point(latLon, zoomLevel){
var x = (latLon.lon + 180) / 360;
var sinLatitude = Math.sin(latLon.lat * Math.PI / 180);
var y = 0.5  Math.log((1 + sinLatitude) / (1  sinLatitude)) / (4 * Math.PI);
var mapSize = MSMapSize(zoomLevel);
return new Point(MSClip(x * mapSize + 0.5, 0, mapSize  1), MSClip(y * mapSize + 0.5, 0, mapSize  1))
}
but I have trouble reversing the formula,
I've got the correct Lontitude but Latitude is wrong
the latitude's maximum is supposed to be 85, but it shows 90 on the function I built
But the point right on the equator shows correctly with Lat 0
the following is my equation reversed from the above formula
p.x & p.y is based on the zoom level
for instance, zoom level 2, mapsize = 2046 and point will be xxx etc...
var mapSize = MSMapSize(mapZoom);
p.x = (p.x + 0.5) / mapSize;
var lon = p.x * 360  180;
p.y = (p.y + 0.5) / mapSize;
var temp = (.5  p.y) * 4 * Math.PI;
temp = Math.pow(10, temp);
var sinLatitude = (temp  1) / (temp + 1);
//alert(sinLatitude);
var lat = Math.asin(sinLatitude) * 180 / (Math.PI);
var lalo = new LatLon(lat, lon);Thursday, November 27, 2008 1:24 AM