0
votes

I programatically create requests to dev.virtualearth.net (Bing static maps). I know the following values:

  • Center Point (Latitude & Longitude)
  • Zoom Level
  • Map Size (X pixels, Y pixels)

After I recieved the map as a bitmap, how do I determine the Coordinates (Latitude and Longitude) of the upper left corner (basically the very first pixel) and the lower right corner (the very last pixel)?

I just need some suggestions or some pseudo code. Note, that while I know the Center Point, Zoom Level and Map Size, these aren't the same for every request.

Thank you.

1

1 Answers

1
votes

You will need to do tile math: https://msdn.microsoft.com/en-us/library/bb259689.aspx

You will need to do the following:

  1. Pass the center point into LatLongToPixelXY method to get the center global pixel value.
  2. Knowing the pixel dimensions of the static image you created, subtract half the width from the x value of the center global pixel value. Do the same with the height and y.
  3. This gives you a new pixel value, pass it into the PixelXYToLatLong to get the coordinate for the top left corner.

That's it :)

I have an old code sample that does this, but retrieves the static image using the old SOAP services rather than the REST services. You can find the blog post here: https://rbrundritt.wordpress.com/2008/10/25/ve-imagery-service-and-custom-icons/ See the LatLongToPixel function code that is half way down the post. That does the above three steps.