Hi Agustin,

Here's how I do it in C# .. it's not perfect (as you loop through the
possabilities) .. but you get the idea .. Sorry the formatting is a
bit off.

        public static int GetZoomLevel(LatLng Center, LatLngBounds
latLngBounds, int width, int height)
        {
            for (int x = 21; x >= 0; x--)
            {
                Point TopRight = new Point(width/2, -height/2);
                Point BottomLeft = new Point(-width / 2,height / 2);
                LatLngBounds mapBounds = new LatLngBounds
(Mercator.XYToLatLng(BottomLeft, Center, x), Mercator.XYToLatLng
(TopRight, Center, x));

                if (mapBounds.NorthEast.Latitude >=
latLngBounds.NorthEast.Latitude && mapBounds.NorthEast.Longitude >=
latLngBounds.NorthEast.Longitude && mapBounds.SouthWest.Latitude <=
latLngBounds.SouthWest.Latitude && mapBounds.SouthWest.Longitude <=
latLngBounds.SouthWest.Longitude)
                {
                    return x;
                }
            }

            throw new ApplicationException("Zoom Level Not Found");
        }

Where the mercator class is

public static class Mercator
    {
        static double offset = 268435456;
        static double radius = offset / Math.PI;

        public static Point LatLngToXY(int width, int height, LatLng
point, LatLng center, int zoomLevel)
        {
            Point result = LatLngToXY(point.Latitude, point.Longitude,
center.Latitude, center.Longitude, zoomLevel);

            result.X += width / 2;
            result.Y += height / 2;

            return result;
        }

        private static Point LatLngToXY(double pointLatitude, double
pointLongitude, double centerLatitude, double centerLongitude, int
zoomLevel)
        {
            int resultX = ((int)(LToX(pointLongitude) - LToX
(centerLongitude))) >> (21 - zoomLevel);
            int resultY = ((int)(LToY(pointLatitude) - LToY
(centerLatitude))) >> (21 - zoomLevel);

            return new Point(resultX, resultY);
        }

        public static LatLng XYToLatLng(Point point, LatLng center,
int zoomLevel)
        {
            return XYToLatLng(point.X, point.Y, center.Longitude,
center.Latitude, zoomLevel);
        }

        private static LatLng XYToLatLng(int x, int y, double
centerLongitude, double centerLatitude, int zoomLevel)
        {
            double resultLat;
            double resultLng;

            resultLat = YToL(LToY(centerLatitude) + (y << (21 -
zoomLevel)));
            resultLng = XToL(LToX(centerLongitude) + (x << (21 -
zoomLevel)));


            return new LatLng(resultLat, resultLng);
        }

        public static double LToX(double x)
        {
            return Math.Round(offset + radius * x * Math.PI / 180);
        }

        public static double LToY(double y)
        {
            return Math.Round(offset - radius * Math.Log((1 + Math.Sin
(y * Math.PI / 180)) / (1 - Math.Sin(y * Math.PI / 180))) / 2);
        }

        public static double XToL(double x)
        {
            return ((Math.Round(x) - offset) / radius) * 180 /
Math.PI;
        }

        public static double YToL(double y)
        {
            return (Math.PI / 2 - 2 * Math.Atan(Math.Exp((Math.Round
(y) - offset) / radius))) * 180 / Math.PI;
        }
    }

Cheers,

RodgerWilko!

On May 5, 10:33 am, Agustin C <[email protected]> wrote:
> Hi,
>
> I was wondering if anyone has documented or seen an example of how to
> calculate the zoom levels for a map without the Google Maps API.
> Sorry, but since this is a server side operation, there is no example
> to show.
>
> Our company has a list of center points that shift day to day based on
> the children each have.  Each child point can change from day to day
> which would change the calculated center point for the parent.  Every
> day we will be calculating the outer boundries by generaing a south
> west and north east point.
>
> In the past, I've implemented something similar to this by taking the
> box and using oGoogleMap.getBoundsZoomLevel(oBounds) to get the level,
> but again I need this to happen at the server side in order to be able
> to use the Google Static Image API to set the center point and it's
> zoom level without having to load the Google Map API client on this
> page.
>
> I'm essentially looking to replicate the calculations mayde by
> getBoundsZoomLevel() logic.
>
> Thanks in advance.
>
> Agustin Colchado
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to