0
votes

I am querying Bing Maps for an image using specific coordinates and a specific size of the image I want returned. However, Bing Maps seem to pad the image to stick to the aspect ratio or something (speculation). How do I get an image of ANY size that just shows the coordinates I query?

Query: http://dev.virtualearth.net//REST/v1/Imagery/Map/Aerial?mapArea=17.946789586870125,-76.86079673253036,18.07139741296038,-76.70156443780112&mapSize=1500,1500&key=

The image this query returns is displayed below, along with the extra padding within the rectangles I drew to highlight the issue. Even if I remove the 'mapSize=1500,1500' I still do not get the exact coordinates queried.

enter image description here
The overlap, or extra padding of the image can be seen from the following two images. Where one image stops, the other image is supposed to begin:
Picture 1 has coordinates of: 17.95, -76.86, 17.98, -76.82.
Picture 2 has coordinages of: 17.95, -76.82, 17.98, -76.78

enter image description here enter image description here

1

1 Answers

1
votes

This is to be expected as the image will be set to one of the 19 zoom levels supported by Bing Maps. An image that includes the bounding box will be returned but it will not always be a night fit. There is no way in the service to have it return an image that fits tightly around the bounding box. However, if the size of the image isn't an issue then their are two options. One is to trim the image afterwards, the other is to calculate the zoom level, center point and map sizes that would work best for the bounding box. This calculation could be done using a bunch of the formula's here: https://msdn.microsoft.com/en-us/library/bb259689.aspx

In addition to this you can also this calculation: https://rbrundritt.wordpress.com/2009/07/21/determining-best-map-view-for-an-array-of-locations/

To start off, calculate the best map view based on an array of locations (corners of your bounding box) and use the max image size supported by the Bing Maps REST Imagery service. From here you will get a zoom level and a center point. You can then use this information to calculate the pixel coordinates of the corners of your bounding box. You can use this to calculate the pixel width and height of your image. Using these dimensions, the zoom level and center point you can then request an static image that will fit your bounding box tightly.

I have put together a code sample that does this for you here: https://code.msdn.microsoft.com/Retrieve-Bing-Maps-image-6a72da30