none
how to generate a map based on a given scale [Bing Map]? RRS feed

  • Question

  •        

    I recently started working with **[*Bing Api*]** in my webService [wcf] in c #.
    I would like to **recover a satellite image of a given scale** with Bing!
    for example

    Scale 1:200 (1 centimeter on the map equal 200 centimeter on the world)

    Of course I found this function that explains how to calculate the image resolution satellite bing but this is not what I'm looking for ..

    Map resolution = 156543.04 meters/pixel * cos(latitude) / (2 ^ zoomlevel)


    Here is my function used to generate my bing map, but I do not know what to send parameter to retrieve an image scale of 1:200.

    *I need :*

    **Scale = 1:200**

    *I search :*

    int **mapSizeHeight** = ?

    int **mapSizeWidth** = ?

    int **zoomLevel** = ?


     public string GetImageMap(double latitude,double longitude,int mapSizeHeight, int mapSizeWidth, int zoomLevel)
            {
                string key = "ddsaAaasm5vwsdfsfd2ySYBxfEFsdfsdfcFh6iUO5GI4v";
                MapUriRequest mapUriRequest = new MapUriRequest();
    
                // Set credentials using a valid Bing Maps key
                mapUriRequest.Credentials = new ImageryService.Credentials();
                mapUriRequest.Credentials.ApplicationId = key;
    
                // Set the location of the requested image
                mapUriRequest.Center = new ImageryService.Location();
                mapUriRequest.Center.Latitude = latitude;
                mapUriRequest.Center.Longitude = longitude;
    
                // Set the map style and zoom level
                MapUriOptions mapUriOptions = new MapUriOptions();
                mapUriOptions.Style = MapStyle.Aerial;
                mapUriOptions.ZoomLevel = zoomLevel;
                mapUriOptions.PreventIconCollision = true;
                // Set the size of the requested image in pixels
                mapUriOptions.ImageSize = new ImageryService.SizeOfint();
                mapUriOptions.ImageSize.Height = mapSizeHeight;
                mapUriOptions.ImageSize.Width = mapSizeWidth;
    
                mapUriRequest.Options = mapUriOptions;
              
                //Make the request and return the URI
                ImageryServiceClient imageryService = new ImageryServiceClient();
                MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);
                return mapUriResponse.Uri;
            }



    King Middle




    • Edited by kingmiddle Monday, March 4, 2013 3:48 PM
    Monday, March 4, 2013 3:11 PM

Answers

  • Simply re-arrange the formula. This will give you this:

    ZoomLevel = log(156543.04 * cos(latitude)/MapResolution)/log(2)

    We can simplify this and set latitude to 0 which will make cos(latitude) = 1

    Thus: ZoomLevel = log(156543.04 /MapResolution)/log(2)


    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Tuesday, March 5, 2013 11:52 AM
    • Marked as answer by kingmiddle Tuesday, March 5, 2013 12:54 PM
    • Unmarked as answer by kingmiddle Tuesday, March 5, 2013 12:56 PM
    • Marked as answer by kingmiddle Tuesday, March 5, 2013 2:29 PM
    Tuesday, March 5, 2013 11:52 AM

All replies

  • You will only be able to generate images of maps for the scales that line up with the zoom levels in Bing Maps as defined here: http://msdn.microsoft.com/en-us/library/aa940990.aspx

    http://rbrundritt.wordpress.com

    Monday, March 4, 2013 4:04 PM
  • Yes I already knew this link, thank you. But the link does not explain how to calculate the resolution and zoom a map using a scale and not the opposite unfortunately for me  ...!

    Map scale = 1 : (ScreenRes pixels/inch * 39.37 inches/meter * 156543.04 meters/pixel * cos(latitude) / (2 ^ zoomlevel))

    Map scale = 1:200 ( I already know this value. No need to calculate )

    Map resolution = 0.125 meter /pixel ( I already know this value. No need to calculate )

    Map zoomLevel = ? ( I need this value )


    King Middle


    • Edited by kingmiddle Tuesday, March 5, 2013 10:08 AM
    Tuesday, March 5, 2013 10:02 AM
  • Simply re-arrange the formula. This will give you this:

    ZoomLevel = log(156543.04 * cos(latitude)/MapResolution)/log(2)

    We can simplify this and set latitude to 0 which will make cos(latitude) = 1

    Thus: ZoomLevel = log(156543.04 /MapResolution)/log(2)


    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Tuesday, March 5, 2013 11:52 AM
    • Marked as answer by kingmiddle Tuesday, March 5, 2013 12:54 PM
    • Unmarked as answer by kingmiddle Tuesday, March 5, 2013 12:56 PM
    • Marked as answer by kingmiddle Tuesday, March 5, 2013 2:29 PM
    Tuesday, March 5, 2013 11:52 AM
  • Thank you very muchRichard.Thisis exactly whatI was looking for

    but what is the log () function?


    King Middle


    • Edited by kingmiddle Tuesday, March 5, 2013 12:55 PM
    Tuesday, March 5, 2013 12:54 PM
  • A log (logarithm) is how you get the inverse of power. http://en.wikipedia.org/wiki/Logarithm

    In JavaScript you can use Math.log: http://www.w3schools.com/jsref/jsref_log.asp


    http://rbrundritt.wordpress.com

    Tuesday, March 5, 2013 1:42 PM
  • Thank you very much again ^^. i Closed this post

    King Middle


    • Edited by kingmiddle Tuesday, March 5, 2013 2:30 PM
    Tuesday, March 5, 2013 2:29 PM
  • Thank you  Richard for a great assistance for me too!
    Monday, March 18, 2013 3:32 AM