public string GetMapUri(double latitude, double longitude, int zoom, string mapStyle, int width, int height)
        {
            ImageryService.Pushpin[] pins    = new ImageryService.Pushpin[1];
            ImageryService.Pushpin   pushpin = new ImageryService.Pushpin();
            pushpin.Location           = new ImageryService.Location();
            pushpin.Location.Latitude  = latitude;
            pushpin.Location.Longitude = longitude;
            pushpin.IconStyle          = "2";
            pins[0] = pushpin;
            MapUriRequest mapUriRequest = new MapUriRequest();

            // Set credentials using a valid Bing Maps Key
            mapUriRequest.Credentials = new ImageryService.Credentials();
            mapUriRequest.Credentials.ApplicationId = "AjKX5fPclkvH3YTYhLImWMour1KISHMrcFVBrXzVsjqwMLiWobOq83esCN1ra0Q0";

            // Set the location of the requested image
            mapUriRequest.Pushpins = pins;
            // Set the map style and zoom level
            MapUriOptions mapUriOptions = new MapUriOptions();

            //mapUriOptions.ZoomLevel = 17;
            switch (mapStyle.ToUpper())
            {
            case "HYBRID":
                mapUriOptions.Style = ImageryService.MapStyle.AerialWithLabels;
                break;

            case "ROAD":
                mapUriOptions.Style = ImageryService.MapStyle.Road;
                break;

            case "AERIAL":
                mapUriOptions.Style = ImageryService.MapStyle.Aerial;
                break;

            default:
                mapUriOptions.Style = ImageryService.MapStyle.Road;
                break;
            }

            mapUriOptions.ZoomLevel = 10;
            // Set the size of the requested image to match the size of the image control
            mapUriOptions.ImageSize        = new ImageryService.SizeOfint();
            mapUriOptions.ImageSize.Height = height;
            mapUriOptions.ImageSize.Width  = width;
            mapUriRequest.Options          = mapUriOptions;

            ImageryServiceClient imageryService = new ImageryServiceClient("BasicHttpBinding_IImageryService");
            MapUriResponse       mapUriResponse = imageryService.GetMapUri(mapUriRequest);

            return(mapUriResponse.Uri);
        }
Example #2
0
        public string GetMapUri(double latitude, double longitude, int zoom, string mapStyle, int width, int height)
        {
            ImageryService.Pushpin[] pins = new ImageryService.Pushpin[1];
            ImageryService.Pushpin pushpin = new ImageryService.Pushpin();
            pushpin.Location = new ImageryService.Location();
            pushpin.Location.Latitude = latitude;
            pushpin.Location.Longitude = longitude;
            pushpin.IconStyle = "2";

            pins[0] = pushpin;

            MapUriRequest mapUriRequest = new MapUriRequest();

            // Set credentials using a valid Bing Maps Key
            mapUriRequest.Credentials = new ImageryService.Credentials();
            mapUriRequest.Credentials.ApplicationId = key;

            // Set the location of the requested image
            mapUriRequest.Pushpins = pins;

            // Set the map style and zoom level
            MapUriOptions mapUriOptions = new MapUriOptions();

            switch (mapStyle.ToUpper())
            {
                case "HYBRID":
                    mapUriOptions.Style = ImageryService.MapStyle.AerialWithLabels;
                    break;
                case "ROAD":
                    mapUriOptions.Style = ImageryService.MapStyle.Road;
                    break;
                case "AERIAL":
                    mapUriOptions.Style = ImageryService.MapStyle.Aerial;
                    break;
                default:
                    mapUriOptions.Style = ImageryService.MapStyle.Road;
                    break;
            }

            mapUriOptions.ZoomLevel = zoom;

            // Set the size of the requested image to match the size of the image control
            mapUriOptions.ImageSize = new ImageryService.SizeOfint();
            mapUriOptions.ImageSize.Height = height;
            mapUriOptions.ImageSize.Width = width;

            mapUriRequest.Options = mapUriOptions;

            ImageryServiceClient imageryService = new ImageryServiceClient("BasicHttpBinding_IImageryService");
            MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);

            return mapUriResponse.Uri;
        }