How to calculate the coordinates of the 4 corners (edge) of the map with BingMap?

Question

• I can work from bing. I can display an image with my bing map coordinates lontitude and latitude.

But I would like to calculate the coordinates of location in the 4 edges of my image. For now the only thing I know is the central point of origin. The problem is that I'm limited to API. I work for a games xna c # and unfortunately can not use the Class Map from microsoft :-(. http://msdn.microsoft.com/en-us/library/hh846504.aspx

I know the following values: (sample value)

LevelZoom: 17

ImageWidth: 800 px

Imageheight: 800 px

Lat: 46.6

Longitude: 7

Is it possible to calculate the coordinates of the 4 corners of my image with these 5 values ​​known? Here is a drawing explaining what I want.

King Middle

Wednesday, March 06, 2013 7:45 PM

• All the math you need is documented here: http://msdn.microsoft.com/en-us/library/bb259689.aspx To calculate the coordinates at the corners simply take the center point and calculate the global pixel coordinate relative to the top left corner of the map (90,-180) using the LatLongToPixelXY method. Then offset this pixel coordinate by the pixel distance to the corners (i.e. width/2, height/2...) and then use the PixelXYToLatLong method to calculate the coordinates.

As for the services. If using the SOAP services you should use the REST services for the imagery. The SOAP service is an old legacy service which is slow and low on features where as the REST services are much faster, have more features and the focus of new developments.

http://rbrundritt.wordpress.com

Friday, March 08, 2013 12:45 PM

All replies

• Hi,

you can easily work out the math for the corners given you know the center point and the width and height of the rect. What API exactly are you using to display(draw) the map?

Thanks,

Viktor Halitsyn

Wednesday, March 06, 2013 9:52 PM
• Ok thanks :). I use webSercice GeoService and ImageryService from Bing.

King Middle

Thursday, March 07, 2013 7:44 AM
• you are very welcome.
cool. though I'd suggest moving to REST services as in here
http://msdn.microsoft.com/en-us/library/ff701721.aspx

Viktor Halitsyn

Friday, March 08, 2013 12:04 AM
• I do not see how it could solve my problem ... How Bing Rest would he calculate the latitude / longitude position of each of my corner of the map?

Here is the REAL solution :

-> found on stackoverflow

```Based on the scale 1.19 m/pixel given by the bing maps api for a level 17 zoom this gives us 800px * 1.19 = 95'000 meters edges (http://msdn.microsoft.com/en-us/library/aa940990.aspx)

You should be able to calculate it this way : (alorithm : http://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters)
```

``` //Position, decimal degrees
lat = 46.6023
lon = 7.0964

R=6378137

// DO THE SAME FOR B C D

//offsets in meters for A
dn = -476
de = -476

//Coordinate offsets in radians
dLat = dn/R                      // -0.0074629942881440144669203562106
dLon = de/(R*Cos(Pi*lat/180))    // -0.00746374633301685016002447644032

//OffsetPosition, decimal degrees
latA = lat + dLat * 180/Pi // 46.174701924759107796879309401922
lonA = lon + dLon * 180/Pi // 6.6687588357618898589751458712973```

King Middle

• Edited by Friday, March 08, 2013 10:03 AM
Friday, March 08, 2013 10:03 AM
• All the math you need is documented here: http://msdn.microsoft.com/en-us/library/bb259689.aspx To calculate the coordinates at the corners simply take the center point and calculate the global pixel coordinate relative to the top left corner of the map (90,-180) using the LatLongToPixelXY method. Then offset this pixel coordinate by the pixel distance to the corners (i.e. width/2, height/2...) and then use the PixelXYToLatLong method to calculate the coordinates.

As for the services. If using the SOAP services you should use the REST services for the imagery. The SOAP service is an old legacy service which is slow and low on features where as the REST services are much faster, have more features and the focus of new developments.

http://rbrundritt.wordpress.com

Friday, March 08, 2013 12:45 PM