c# - It is possible to request a bing map image from a given size ( meters )? -


hello work on game based on map generation bing.

the problem is: card generated based on address given user, after generate 1km2 card (1000m wide , 1000m long).

unfortunately found no bing api retrieve map defined size in meters. can define "level zoom" , resolution.

here's use (from microsoft bing api tile code library example):

bing maps tile system

// bing map (resolution max. 834 pixel) zoom level 16 var stream = await httpclient.getstreamasync("api/newmap/?latitude=46.6052284&longitude=7.0967002&mapsizeheight=834&mapsizewidth=834&zoomlevel=16");     // calculated "latitudecentre" , "zoom level" , 0.8 meter/pixel double meterperpixel = tilesystem.groundresolution(latitudecentre, 16); 

for example (834/834 pixel) , zoom level 16 => gives me scale of 0.8 meter / pixel. can not generate 1 meter / pixel map. think solution problem exist?

i hope if yes ^^ :-)

ok , yes it's possible !! take time make function solve myself . shocked , nobody has never ask question , , microsoft never post code . think function can usefull .

private void setboundingboxlocationandzoom(double latitudecentre)     {         // 1024/1024 meters         double desiredmapsize = 1024.0;           int bestmatchmapsize = 0;         int bestmatchmapresolution = 0;         int bestmatchmapzoom = 0;            //starts largest zoom , ending smallest (remote) (min zoomlevel [1])         // 1 - 21         (int zoom = 21; zoom >= 1; zoom--)         {              //starts highest resolution , ending smallest (min pixel 80/80)             // 80 - 834             (int resolution = 834; resolution >= 80; resolution--)             {                 double meterperpixel = tilesystem.groundresolution(latitudecentre, zoom);                 double mapsize = meterperpixel * resolution;                  if(math.abs(desiredmapsize - mapsize) < math.abs(desiredmapsize - bestmatchmapsize))                 {                     bestmatchmapsize = (int)mapsize;                     bestmatchmapresolution = resolution;                     bestmatchmapzoom = zoom;                 }             }         }           zoomlevel = bestmatchmapzoom;         sizemapinmeter = bestmatchmapsize;         resolutionmap = bestmatchmapresolution;        }      /// <summary>         /// determines ground resolution (in meters per pixel) @ specified         /// latitude , level of detail.         /// </summary>         /// <param name="latitude">latitude (in degrees) @ measure         /// ground resolution.</param>         /// <param name="levelofdetail">level of detail, 1 (lowest detail)         /// 23 (highest detail).</param>         /// <returns>the ground resolution, in meters per pixel.</returns>         public static double groundresolution(double latitude, int levelofdetail)         {             latitude = clip(latitude, minlatitude, maxlatitude);             return math.cos(latitude * math.pi / 180) * 2 * math.pi * earthradius / mapsize(levelofdetail);         } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -