Hi,<br><br>I am developing an application using C#.Net. I have to display map for a given location and I have built the code to calculate grid of tiles that I need to pull from tile server and display. However, I have to crop out a rectangle within the square grid of the map tiles. Also, I have to calculate the bounding box for the inner rectangle.<br>
<br>Here is my approach:<br><br>1) I get the lat lon values for the top-left corner and the bottom-left corner of the square tile grid<br>     <br>     latlon1<br>     latlon2<br><br>2) Convert the lat/lon coordinates to UTM coordinates so that we can find out a radius value of a imaginative circle circumscribing the square tilegrid:<br>
<br>   radius_in_meters = utm2.Easting - utm1.Easting<br><br>3) For the inner rectangle sides calculate the fractions:<br>   <br>    viewX = (rectangle.width/256 * number_of_tiles_in_grid)<br>    viewY =  (rectangle.height/256 * number_of_tiles_in_grid)<br>
<br>4) Radius for the fractions:<br><br>     radiusX = (radius_in_meters/ 1000) * viewX<br>     radiusY = (radius_in_meters/ 1000) * viewY<br><br>5) Convert to degrees:<br><br>      degreesOfRadiusX = (radiusX / 111.111)<br>
      degreesOfRadiusY = (radiusY / 111.111)<br><br>      degreesOfLatY = degreesOfRadiusY * Math.Cos((center.lat* Math.PI) / 180);<br><br>6) Calculate bounding box:<br><br>  longitudes:<br>        bbox_lon[0] = (center.lon- degreesOfRadiusX)<br>
        bbox_lon[1] = (center.lon+ degreesOfRadiusX)<br><br>  latitudes:<br>          bbox_lat[0] = (center.lat- degreesOfLatY);<br>          bbox_lat[1] = (center.lat+ degreesOfLatY);<br> <br>My question:<br><br>The bounding box seem to be ok but not accurate. Each location within the box is off by quite a tens of meters (20-30). <br>
Is there a better (or simpler?) way of calculating the bounding box for a clipped rectangle within the square grid of the map tilegrid?<br>I referred to the opelayers javascript but could not find a function for the OSM layer.<br>
<br>Any suggestions would be of great help, thanks...<br><br>- Vishwa<br><br>  <br><br><br><br>