public DownloadedFile GetMapImageByLocation(string Location, int Zoom, string MapStyle, int Width, int Height, string MapLayer, string ImageFormat = "jpeg", bool DeclutterPins = false)
        {
            BingResult bing = SearchByLocation(Location, 1);

            if (bing == null || bing.resourceSets == null || bing.resourceSets.Count() < 1 || bing.resourceSets[0].resources == null || bing.resourceSets[0].resources.Count() < 1)
            {
                return(null);
            }
            PushPin p = new PushPin()
            {
                //Latitude = float.Parse(this.Lat),
                //Longitude = float.Parse(this.Lon),
                Latitude  = decimal.Parse(bing.resourceSets[0].resources[0].point.coordinates[0]).ToString("#.######"),
                Longitude = decimal.Parse(bing.resourceSets[0].resources[0].point.coordinates[1]).ToString("#.######")
            };
            List <PushPin> pins = new List <PushPin>();

            pins.Add(p);

            return(GetMapImage(GetImageUrl(bing.resourceSets[0].resources[0].point.coordinates[0].ToString(), bing.resourceSets[0].resources[0].point.coordinates[1].ToString(), Zoom, Width, Height, MapLayer, pins, MapStyle, ImageFormat, DeclutterPins, 0)));
        }
        public BingMaps GetMapImageByLatLon()
        {
            /* need to:
             * pushpin co-ordinates
             * pushpint label
             * map type - aerialwithlabels, etc
             * image format - jpeg, png,
             * map layer
             * */

            try
            {
                float.Parse(this.Lat);
                float.Parse(this.Lon);
            }
            catch (Exception ex)
            {
                this.ResultStatus  = "Error";
                this.ResultMessage = "Latitude and Longitude must be supplied as a float xxx.xxxxxx";
                return(this);
            }


            BingMapsHelper Bing = new BingMapsHelper(ServiceConfiguration["BingMapsKey"].ToString());
            PushPin        p    = new PushPin()
            {
                //Latitude = float.Parse(this.Lat),
                //Longitude = float.Parse(this.Lon),
                Latitude  = this.Lat,
                Longitude = this.Lon,
            };
            List <PushPin> pins = new List <PushPin>();

            pins.Add(p);

            DownloadedFile file = Bing.GetMapImage(decimal.Parse(this.Lat).ToString(_decimalFormat), decimal.Parse(this.Lon).ToString(_decimalFormat), this.ImageZoom, this.MapStyle, this.ImageWidth, this.ImageHeight, "", pins, this.ImageFormat, false);

            //BingResult res = Bing.GetMapImageMetadata(decimal.Parse(this.Lat).ToString(_decimalFormat), decimal.Parse(this.Lon).ToString(_decimalFormat), this.ImageZoom, this.MapStyle, this.ImageWidth, this.ImageHeight, "", pins, this.ImageFormat, false);
            //BingResult res = Bing.SearchByPoint(decimal.Parse(this.Lat).ToString(_decimalFormat), decimal.Parse(this.Lon).ToString(_decimalFormat), "");
            //BingResult res = Bing.SearchByPoint(this.Lat, this.Lon, "");


            //if (res == null)
            //{
            //    this.ResultStatus = "Error";
            //    this.ResultMessage = "Failed to download and deserialize result";
            //    return this;
            //}

            if (file == null)
            {
                this.ResultStatus  = "OK";
                this.ResultMessage = "No results";
                return(this);
            }

            //if (res.resourceSets == null || res.resourceSets.Count() < 1 || res.resourceSets[0].resources == null || res.resourceSets[0].resources.Count() < 1)
            //{
            //    Resource resource = res.resourceSets[0].resources[0];

            //    MapBingMaps(this, resource);
            //}

            this.ImageBase64 = file.Base64;
            this.ImageSize   = file.Size;
            string filename = Guid.NewGuid() + file.FileExtension;

            this.ImageFilename    = filename;
            this.ImageContentType = file.ContentType;
//            this.EstimatedTotal = res.resourceSets[0].estimatedTotal;

            FileProperty fp = new FileProperty()
            {
                Content  = this.ImageBase64,
                FileName = filename
            };

            this.Image = fp.Value.ToString();

            // nothing specied so set defaults
            if (this.ImageWidth == 0)
            {
                this.ImageWidth = 300;
            }
            if (this.ImageHeight == 0)
            {
                this.ImageHeight = 300;
            }
            if (this.ImageZoom == 0)
            {
                this.ImageZoom = 10;
            }

            this.ResultStatus = "OK";

            return(this);
        }