Geo X Y Locations

Dec 17, 2009 at 6:42 AM

Hey Guys,

I got a small problem :P I have no idea how to get the Geo Location of where the user is looking. Im using a self made Multiscaleimage source with my company's map tiles and its not of the whole world but just our country. AS it was self built I know what the geocoded X and Y co-ordinates are for the top left corner at the given Tile Levels. But for the life of me The math for the viewportwidth and viewportorigin escapes me. I cant figure out where the user is looking. This should be a simple math formula if anyone can help me with this. Thanks!!!!

Coordinator
Dec 17, 2009 at 9:31 PM

So you need to know the projection of the map images you have produced, the math may not be as simple as you think.

We use the spherical mecator projection that assumes the world is a sphere and makes the math easy, we can simple divided evenly for longitude but latitude is more complex. I'm assuming you're going to need to apply some sort of offset due to now being the whole world.

The MSI control simply works on 1 being the full size, 0.5 would be zoomed in 200%. Feel free to use the math we have here but we don't have support for an offset. If it makes it simplier this is some basic math to calculate XY in meters from Lat/Long for the Sperical mecator projection:

       private static double[] MercatorEllipsoid(LatLong pos)
        {
            return new[] { LongitudeToX(pos.Longitude), LatitudeToY(pos.Latitude) };
        }

        private const double earthRadius = 6378137; //The radius of the earth - should never change!

        public static double LatitudeToY(double lat)
        {
            double sinLat = Math.Sin(DegToRad(lat));
            return earthRadius / 2 * Math.Log((1 + sinLat) / (1 - sinLat));
        }

        public static double LongitudeToX(double lon)
        {
            return earthRadius * DegToRad(lon);
        }

        private static double DegToRad(double d)
        {
            return d * Math.PI / 180.0;
        }