Example #1
0
        //The Imagery Service
        private string GetImagery(string locationString)
        {
            string        key           = "ApwndqJgdJ9M1Bpb7d_ihBwXW-J0N3HdXrZvFZqvFtmeYN5DewRoGPI7czgFo5Sh";
            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.Center = new ImageryService.Location();
            string[] digits = locationString.Split(',');
            mapUriRequest.Center.Latitude  = double.Parse(digits[0].Trim());
            mapUriRequest.Center.Longitude = double.Parse(digits[1].Trim());

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

            mapUriOptions.Style     = MapStyle.AerialWithLabels;
            mapUriOptions.ZoomLevel = 17;

            // Set the size of the requested image in pixels
            mapUriOptions.ImageSize        = new ImageryService.SizeOfint();
            mapUriOptions.ImageSize.Height = 200;
            mapUriOptions.ImageSize.Width  = 300;

            mapUriRequest.Options = mapUriOptions;

            //Make the request and return the URI
            ImageryServiceClient imageryService = new ImageryServiceClient("BasicHttpBinding_IImageryService");
            MapUriResponse       mapUriResponse = imageryService.GetMapUri(mapUriRequest);

            return(mapUriResponse.Uri);
        }
Example #2
0
    private string GetImagery(string locationString)
    {
        string        key           = "ArLeGdHOcc5h7j3L4W37oFGcU9E-LF3tAZi4o0DfhXbPJ8aiyTGbIDNHex08R2u7";
        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.Center = new ImageryService.Location();
        string[] digits = locationString.Split(',');
        mapUriRequest.Center.Latitude  = double.Parse(digits[0].Trim());
        mapUriRequest.Center.Longitude = double.Parse(digits[1].Trim());

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

        mapUriOptions.Style     = MapStyle.AerialWithLabels;
        mapUriOptions.ZoomLevel = 17;

        // Set the size of the requested image in pixels
        mapUriOptions.ImageSize        = new ImageryService.SizeOfint();
        mapUriOptions.ImageSize.Height = 200;
        mapUriOptions.ImageSize.Width  = 300;

        mapUriRequest.Options = mapUriOptions;

        //Make the request and return the URI
        ImageryServiceClient imageryService = new ImageryServiceClient("BasicHttpBinding_IImageryService");
        MapUriResponse       mapUriResponse = imageryService.GetMapUri(mapUriRequest);

        return(mapUriResponse.Uri);
    }
        private string GetMapUri(double latitude, double longitude, int zoom, string mapStyle, int width, int height)
        {
            MvcSourceblog.ImageryServices.Pushpin[] pins    = new MvcSourceblog.ImageryServices.Pushpin[1];
            MvcSourceblog.ImageryServices.Pushpin   pushpin = new MvcSourceblog.ImageryServices.Pushpin();
            pushpin.Location           = new MvcSourceblog.ImageryServices.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 ImageryServices.Credentials();
            mapUriRequest.Credentials.ApplicationId = "AhjlMbKnHDlgTASkyk750YRs5wR3_1gN2hEz6pahnE7Iiurq_DzrE4hDUgBxrtfN";


            // 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 = MvcSourceblog.ImageryServices.MapStyle.AerialWithLabels;
                break;

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

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

            case "BirdseyeWithLabels_v1":
                mapUriOptions.Style = MvcSourceblog.ImageryServices.MapStyle.BirdseyeWithLabels_v1;
                break;

            default:
                mapUriOptions.Style = MvcSourceblog.ImageryServices.MapStyle.Road;
                break;
            }

            mapUriOptions.ZoomLevel = 10;
            // Set the size of the requested image to match the size of the image control
            mapUriOptions.ImageSize        = new MvcSourceblog.ImageryServices.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 #4
0
        async public static Task <string> GetMapUri(double latitude, double longitude, int zoom, string mapStyle, int width, int height)
        {
            var pins    = new Pushpin[1];
            var pushpin = new Pushpin();

            pushpin.Location           = new Location();
            pushpin.Location.Latitude  = latitude;
            pushpin.Location.Longitude = longitude;
            pushpin.IconStyle          = "2";
            pins[0] = pushpin;

            var mapUriRequest = new MapUriRequest
            {
                Credentials = new Credentials(),
                Pushpins    = pins
            };

            mapUriRequest.Credentials.ApplicationId = App.Self.APIKEY;

            var mapUriOptions = new MapUriOptions
            {
                ZoomLevel = zoom,
                ImageSize = new SizeOfint()
            };

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

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

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

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

            mapUriOptions.ImageSize.Height = height;
            mapUriOptions.ImageSize.Width  = width;

            mapUriRequest.Options = mapUriOptions;

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

            return(mapUriResponse.Uri);
        }
Example #5
0
        private string GetMapUri(double latitude, double longitude, int zoom, string mapStyle, int width, int height)
        {
            ImageryServices.Pushpin[] pins    = new ImageryServices.Pushpin[1];
            ImageryServices.Pushpin   pushpin = new ImageryServices.Pushpin();
            pushpin.Location           = new ImageryServices.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 ImageryServices.Credentials();
            mapUriRequest.Credentials.ApplicationId = "7Xe5dWLJW6JIhH6jDYR7~6wrgqqAAstaYhxwKEyAB6g~AhB0MhPMBgrTWhG-cxBqbFxaJe92xk7oGVnJPfBckupM4wWTauJQIMkjs5Fs_Z5u";

            // 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 = ImageryServices.MapStyle.AerialWithLabels;
                break;

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

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

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

            mapUriOptions.ZoomLevel = 15;
            // Set the size of the requested image to match the size of the image control
            mapUriOptions.ImageSize        = new ImageryServices.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);
        }
        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);
        }
        private BitmapImage GetMap(string address)
        {
            var geocodeClient = ServiceLocator.Current.GetInstance<IGeocodeService>();

            var geocodeRequest = new GeocodeRequest()
            {
                Credentials = new Bing.Maps.GeocodeService.Credentials()
                {
                    ApplicationId = Settings.Default.BingMapsKey
                },
                Query = address
            };


            var geocodeResponse = geocodeClient.Geocode(geocodeRequest);


            var imageryClient = ServiceLocator.Current.GetInstance<IImageryService>();

            var imageryRequest = new MapUriRequest()
            {
                Credentials = new Bing.Maps.ImageryService.Credentials()
                {
                    ApplicationId = Settings.Default.BingMapsKey
                },
                Center = new Bing.Maps.ImageryService.Location()
                {
                    Latitude =
                        geocodeResponse.Results[0].Locations[0].Latitude,
                    Longitude =
                        geocodeResponse.Results[0].Locations[0].Longitude
                },
                Options = new MapUriOptions()
                {
                    Style = MapStyle.AerialWithLabels,
                    ZoomLevel = 17,
                    ImageSize = new Bing.Maps.ImageryService.SizeOfint()
                    {
                        Height = 512,
                        Width = 512
                    }
                }
            };

            var mapUriResponse = imageryClient.GetMapUri(imageryRequest);

            return new BitmapImage(new Uri(mapUriResponse.Uri), new RequestCachePolicy(RequestCacheLevel.BypassCache));
        }
Example #8
0
        public static Stream getMapImage(double?latitude, double?longitude)
        {
            const string map_credentials = "ApjKKP3xo-UePHYy4EWVj7kzRUAx40rbKSGGCzw-E_jK2YAtyhs5Na0_PunRgr2Y";

            bingMapImageryService.MapUriRequest mapUriRequest = new MapUriRequest();
            Stream imageStream = null;


            // Set credentials using a valid Bing Maps key
            mapUriRequest.Credentials = new bingMapImageryService.Credentials();
            mapUriRequest.Credentials.ApplicationId = map_credentials;                  // "ApjKKP3xo-UePHYy4EWVj7kzRUAx40rbKSGGCzw-E_jK2YAtyhs5Na0_PunRgr2Y";

            bingMapImageryService.Pushpin[] pins    = new bingMapImageryService.Pushpin[1];
            bingMapImageryService.Pushpin   pushpin = new bingMapImageryService.Pushpin();
            pushpin.Location           = new bingMapImageryService.Location();
            pushpin.Location.Latitude  = (double)latitude;
            pushpin.Location.Longitude = (double)longitude;
            pushpin.IconStyle          = "2";
            pins[0] = pushpin;

            mapUriRequest.Pushpins = pins;

            //// Set the map style and zoom level
            bingMapImageryService.MapUriOptions mapUriOptions = new bingMapImageryService.MapUriOptions();
            mapUriOptions.Style     = bingMapImageryService.MapStyle.AerialWithLabels;
            mapUriOptions.ZoomLevel = 16;

            // Set the size of the requested image to match the size of the image control
            mapUriOptions.ImageSize        = new bingMapImageryService.SizeOfint();
            mapUriOptions.ImageSize.Height = 350;
            mapUriOptions.ImageSize.Width  = 600;
            mapUriRequest.Options          = mapUriOptions;

            bingMapImageryService.ImageryServiceClient imageryService = new bingMapImageryService.ImageryServiceClient("BasicHttpBinding_IImageryService");

            // Make the image request
            bingMapImageryService.MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);
            string mapUri = mapUriResponse.Uri;

            // get image from uri
            imageStream = downloadImage(mapUri);

            //if (imageStream != null)
            //     mapImage = Image.FromStream(imageStream);

            return(imageStream);
        }
Example #9
0
        public static Stream getMapImage(double? latitude, double? longitude)
        {
            const string map_credentials = "ApjKKP3xo-UePHYy4EWVj7kzRUAx40rbKSGGCzw-E_jK2YAtyhs5Na0_PunRgr2Y";
            bingMapImageryService.MapUriRequest mapUriRequest = new MapUriRequest();
            Stream imageStream = null;

            // Set credentials using a valid Bing Maps key
            mapUriRequest.Credentials = new bingMapImageryService.Credentials();
            mapUriRequest.Credentials.ApplicationId = map_credentials;	// "ApjKKP3xo-UePHYy4EWVj7kzRUAx40rbKSGGCzw-E_jK2YAtyhs5Na0_PunRgr2Y";

                    bingMapImageryService.Pushpin[] pins = new bingMapImageryService.Pushpin[1];
            bingMapImageryService.Pushpin pushpin = new bingMapImageryService.Pushpin();
            pushpin.Location = new bingMapImageryService.Location();
            pushpin.Location.Latitude = (double)latitude;
            pushpin.Location.Longitude = (double)longitude;
            pushpin.IconStyle = "2";
            pins[0] = pushpin;

            mapUriRequest.Pushpins = pins;

            //// Set the map style and zoom level
            bingMapImageryService.MapUriOptions mapUriOptions = new bingMapImageryService.MapUriOptions();
            mapUriOptions.Style = bingMapImageryService.MapStyle.AerialWithLabels;
            mapUriOptions.ZoomLevel = 16;

            // Set the size of the requested image to match the size of the image control
            mapUriOptions.ImageSize = new bingMapImageryService.SizeOfint();
            mapUriOptions.ImageSize.Height = 350;
            mapUriOptions.ImageSize.Width = 600;
            mapUriRequest.Options = mapUriOptions;

            bingMapImageryService.ImageryServiceClient imageryService = new bingMapImageryService.ImageryServiceClient("BasicHttpBinding_IImageryService");

            // Make the image request
            bingMapImageryService.MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);
            string mapUri = mapUriResponse.Uri;

            // get image from uri
            imageStream = downloadImage(mapUri);

            //if (imageStream != null)
            //     mapImage = Image.FromStream(imageStream);

            return imageStream;
        }
Example #10
0
    public static BitmapImage GetImagery(XYPoint point, double dx, double dy)
    {
      
      try
      {
        string key = "ArfYQbvMgvi7NOpxSAuS3lkBlVc3NqzgBcVo-yxNyr_KPVJbhwR22c9cVfG7AnwY";
        MapUriRequest mapUriRequest = new MapUriRequest();

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

        // Set the location of the requested image
        mapUriRequest.Center = new Location();
        mapUriRequest.Center.Latitude = point.Latitude;
        mapUriRequest.Center.Longitude = point.Longitude;

        // Set the map style and zoom level
        MapUriOptions mapUriOptions = new MapUriOptions();
        mapUriOptions.Style = MapStyle.AerialWithLabels_v1;
        mapUriOptions.ZoomLevel = 13;

        // Set the size of the requested image in pixels
        mapUriOptions.ImageSize = new SizeOfint();
        mapUriOptions.ImageSize.Height = (int)(dy / 19.11); //19.11 to get meters
        mapUriOptions.ImageSize.Width = (int)(dx / 19.11);


        mapUriRequest.Options = mapUriOptions;
        //Make the request and return the URI
        ImageryServiceClient imageryService = new ImageryServiceClient("BasicHttpBinding_IImageryService");
        MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);
        return new BitmapImage(new Uri(mapUriResponse.Uri));      
      }
      catch (Exception e)
      {
        return null;
      }
    }
Example #11
0
        public static BitmapImage GetImagery(XYPoint point, double dx, double dy)
        {
            try
            {
                string        key           = "ArfYQbvMgvi7NOpxSAuS3lkBlVc3NqzgBcVo-yxNyr_KPVJbhwR22c9cVfG7AnwY";
                MapUriRequest mapUriRequest = new MapUriRequest();

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

                // Set the location of the requested image
                mapUriRequest.Center           = new Location();
                mapUriRequest.Center.Latitude  = point.Latitude;
                mapUriRequest.Center.Longitude = point.Longitude;

                // Set the map style and zoom level
                MapUriOptions mapUriOptions = new MapUriOptions();
                mapUriOptions.Style     = MapStyle.AerialWithLabels_v1;
                mapUriOptions.ZoomLevel = 13;

                // Set the size of the requested image in pixels
                mapUriOptions.ImageSize        = new SizeOfint();
                mapUriOptions.ImageSize.Height = (int)(dy / 19.11); //19.11 to get meters
                mapUriOptions.ImageSize.Width  = (int)(dx / 19.11);


                mapUriRequest.Options = mapUriOptions;
                //Make the request and return the URI
                ImageryServiceClient imageryService = new ImageryServiceClient("BasicHttpBinding_IImageryService");
                MapUriResponse       mapUriResponse = imageryService.GetMapUri(mapUriRequest);
                return(new BitmapImage(new Uri(mapUriResponse.Uri)));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Example #12
0
        public static void LoadMap(EventHandler<GetMapUriCompletedEventArgs> callback, double latitude, double longitude, int width, int height)
        {
            if(string.IsNullOrEmpty(ApplicationId))
            {
                MessageBox.Show("You need to get bing maps developer id http://www.bing.com/developers");
                return;
            }

            MapUriRequest mapUriRequest = new MapUriRequest();

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

            // Set the location of the requested image
            mapUriRequest.Center = new dev.virtualearth.net.webservices.v1.common.Location();
            mapUriRequest.Center.Latitude = latitude;
            mapUriRequest.Center.Longitude = longitude;

            // Set the map style and zoom level
            MapUriOptions mapUriOptions = new MapUriOptions();
            mapUriOptions.Style = MapStyle.Road;
            mapUriOptions.ZoomLevel = 16;

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

            mapUriRequest.Options = mapUriOptions;

            ImageryServiceClient imageryService = new ImageryServiceClient("BasicHttpBinding_IImageryService");

            // Make the image request
            imageryService.GetMapUriCompleted += callback;
            imageryService.GetMapUriAsync(mapUriRequest);
        }
Example #13
0
        private string GetImagery(string locationString)
        {
            string        key           = "AnMBF3YY-9Cu2a6Og_vid1aCqNpho_WUux8hnOKgtYAK7zFR-WUtXXz31fxPNaCP";
            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.Center = new ImageryService.Location();
            string[] digits = locationString.Split(',');
            mapUriRequest.Center.Latitude  = double.Parse(digits[0].Trim());
            mapUriRequest.Center.Longitude = double.Parse(digits[1].Trim());

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

            mapUriOptions.Style     = MapStyle.AerialWithLabels;
            mapUriOptions.ZoomLevel = 13;

            // Set the size of the requested image in pixels
            mapUriOptions.ImageSize        = new ImageryService.SizeOfint();
            mapUriOptions.ImageSize.Height = 400;
            mapUriOptions.ImageSize.Width  = 600;

            mapUriRequest.Options = mapUriOptions;



            //Make the request and return the URI
            ImageryServiceClient imageryService = new ImageryServiceClient("BasicHttpBinding_IImageryService");
            MapUriResponse       mapUriResponse = imageryService.GetMapUri(mapUriRequest);

            return(mapUriResponse.Uri);
        }
        private string GetImagery(string locationString)
        {
            string key = "l4o5yybDpLNG7xrsTmoP~A0DSZhcYTwcaKvEUgBi44g~AsAjqiCU7gZND03eLCfpdqNDGFXfMdzqXYLFVEGnFy1SgQSlDA8ld0BpbCgI4JsD";
            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.Center = new ImageryService.Location();

            GeocodeService.Location loc = this.GeocodeAddressGetLocation(locationString);

            if (loc != null)
            {
                mapUriRequest.Center.Latitude = loc.Latitude;
                mapUriRequest.Center.Longitude = loc.Longitude;
            }

            // Set the map style and zoom level
            MapUriOptions mapUriOptions = new MapUriOptions();
            mapUriOptions.Style = MapStyle.Road;
            mapUriOptions.ZoomLevel = 15;

            // Set the size of the requested image in pixels
            mapUriOptions.ImageSize = new ImageryService.SizeOfint();
            mapUriOptions.ImageSize.Height = 500;
            mapUriOptions.ImageSize.Width = 500;

            mapUriRequest.Options = mapUriOptions;

            //Make the request and return the URI
            ImageryServiceClient imageryService = new ImageryServiceClient("BasicHttpBinding_IImageryService");
            MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);
            return mapUriResponse.Uri;
        }
Example #15
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;
        }
Example #16
0
        //private GeocodeService.Location GeocodeAddress(string address)
        //{
        //    GeocodeRequest geocodeRequest = new GeocodeRequest();
        //    // Set the credentials using a valid Bing Maps Key
        //    geocodeRequest.Credentials = new GeocodeService.Credentials();
        //    geocodeRequest.Credentials.ApplicationId = key;
        //    // Set the full address query
        //    geocodeRequest.Query = address;
        //    // Set the options to only return high confidence results
        //    ConfidenceFilter[] filters = new ConfidenceFilter[1];
        //    filters[0] = new ConfidenceFilter();
        //    filters[0].MinimumConfidence = GeocodeService.Confidence.High;
        //    GeocodeOptions geocodeOptions = new GeocodeOptions();
        //    geocodeOptions.Filters = filters;
        //    geocodeRequest.Options = geocodeOptions;
        //    // Make the geocode request
        //    GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
        //    GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);
        //    if (geocodeResponse.Results.Length > 0)
        //        if (geocodeResponse.Results[0].Locations.Length > 0)
        //            return geocodeResponse.Results[0].Locations[0];
        //    return null;
        //}
        public string GetImagery(string locationString)
        {
            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.Center = new ImageryService.Location();
            string[] digits = locationString.Split(',');
            mapUriRequest.Center.Latitude = double.Parse(digits[0].Trim());
            mapUriRequest.Center.Longitude = double.Parse(digits[1].Trim());

            // Set the map style and zoom level
            MapUriOptions mapUriOptions = new MapUriOptions();
            mapUriOptions.Style = MapStyle.AerialWithLabels;
            mapUriOptions.ZoomLevel = 17;

            // Set the size of the requested image in pixels
            mapUriOptions.ImageSize = new ImageryService.SizeOfint();
            mapUriOptions.ImageSize.Height = 200;
            mapUriOptions.ImageSize.Width = 300;

            mapUriRequest.Options = mapUriOptions;

            //Make the request and return the URI
            ImageryServiceClient imageryService = new ImageryServiceClient("BasicHttpBinding_IImageryService");
            MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);
            return mapUriResponse.Uri;
        }
        /// <summary>
        /// Get Bing Map Image
        /// </summary>
        protected override void GetMapInternal()
        {
            try
            {
                MapUriOptions mapUriOptions = new MapUriOptions
                {
                    Style = Satellite ? MapStyle.AerialWithLabels : MapStyle.Road,
                    StyleSpecified = true,
                    ZoomLevel = Zoom,
                    ZoomLevelSpecified = true,
                    ImageType = ImageType.Jpeg,
                    ImageTypeSpecified = true,
                    ImageSize = new SizeOfint
                    {
                        Width = Width,
                        WidthSpecified = true,
                        Height = Height,
                        HeightSpecified = true
                    }
                };
                MapUriRequest mapUriRequest = new MapUriRequest
                {
                    Credentials = new Credentials
                    {
                        Token = TokenService.GetToken(Username, Password)
                    },
                    Center = new Location
                    {
                        Latitude = Latitude,
                        LatitudeSpecified = true,
                        Longitude = Longitude,
                        LongitudeSpecified = true
                    },
                    Options = mapUriOptions
                };
                using (ImageryService imageryService = new ImageryService())
                {
                    MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);
                    Log.Info("MapService.GetMap", "URL: {0}", mapUriResponse.Uri);

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mapUriResponse.Uri);
                    request.Credentials = new NetworkCredential(Username, Password);
                    request.AllowAutoRedirect = true;
                    request.ReadWriteTimeout = 5000;
                    request.Method = "GET";
                    request.Timeout = 5000;
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        using (Stream stream = response.GetResponseStream())
                        {
                            if (MapDownloaded != null)
                            {
                                MapDownloaded(this, new MapEventArgs(new Bitmap(stream), true));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("MapService.GetMap", "Exception: {0}", ex.Message);
                if (MapDownloaded != null)
                {
                    MapDownloaded(this, new MapEventArgs(null, false));
                }
            }
        }