public List <BingMaps> SearchByLatLonList()
        {
            List <BingMaps> results = new List <BingMaps>();

            if (string.IsNullOrWhiteSpace(this.IncludeEntityTypes))
            {
                this.IncludeEntityTypes = "";
            }

            BingMapsHelper Bing = new BingMapsHelper(ServiceConfiguration["BingMapsKey"].ToString());

            BingResult res = Bing.SearchByPoint(decimal.Parse(this.Lat).ToString(_decimalFormat), decimal.Parse(this.Lon).ToString(_decimalFormat), this.IncludeEntityTypes);

            if (res == null || res.resourceSets == null || res.resourceSets.Count() < 1 || res.resourceSets[0].resources == null || res.resourceSets[0].resources.Count() < 1)
            {
                return(results);
            }

            foreach (Resource resource in res.resourceSets[0].resources)
            {
                BingMaps map = new BingMaps();
                MapBingMaps(map, resource);
                map.Lat = this.Lat;
                map.Lon = this.Lon;
                map.IncludeEntityTypes = this.IncludeEntityTypes;
                map.EstimatedTotal     = res.resourceSets[0].estimatedTotal;
                map.ResultStatus       = "OK";
                results.Add(map);
            }

            return(results);
        }
        public List <BingMaps> SearchByLocationList()
        {
            List <BingMaps> results = new List <BingMaps>();

            int max = 10;

            if (this.MaxResults > 0)
            {
                max = this.MaxResults;
            }

            BingMapsHelper Bing = new BingMapsHelper(ServiceConfiguration["BingMapsKey"].ToString());

            BingResult res = Bing.SearchByLocation(this.Query, max);

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

            //if (res.resourceSets == null || res.resourceSets.Count() < 1 || res.resourceSets[0].resources.Count() < 1)
            //{
            //    this.ResultStatus = "OK";
            //    this.ResultMessage = "No results";
            //}

            if (res == null || res.resourceSets == null || res.resourceSets.Count() < 1 || res.resourceSets[0].resources == null || res.resourceSets[0].resources.Count() < 1)
            {
                return(results);
            }

            foreach (Resource resource in res.resourceSets[0].resources)
            {
                BingMaps map = new BingMaps();
                MapBingMaps(map, resource);
                map.Query          = this.Query;
                map.MaxResults     = this.MaxResults;
                map.EstimatedTotal = res.resourceSets[0].estimatedTotal;
                map.ResultStatus   = "OK";
                results.Add(map);
            }

            return(results);
        }
        private void MapBingMaps(BingMaps bm, Resource resource)
        {
            bm.LocationName = resource.name;
            //bm.PhoneNumber = resource.address
            //bm.WebSite =

            if (resource.address != null)
            {
                if (!string.IsNullOrWhiteSpace(resource.address.addressLine))
                {
                    bm.AddressLine = resource.address.addressLine;
                }

                if (!string.IsNullOrWhiteSpace(resource.address.adminDistrict))
                {
                    bm.AdminDistrict = resource.address.adminDistrict;
                }

                if (!string.IsNullOrWhiteSpace(resource.address.adminDistrict2))
                {
                    bm.AdminDistrict2 = resource.address.adminDistrict2;
                }

                if (!string.IsNullOrWhiteSpace(resource.address.countryRegion))
                {
                    bm.CountryRegion = resource.address.countryRegion;
                }

                if (!string.IsNullOrWhiteSpace(resource.address.countryRegionIso2))
                {
                    bm.CountryRegionIso2 = resource.address.countryRegionIso2;
                }

                if (!string.IsNullOrWhiteSpace(resource.address.formattedAddress))
                {
                    bm.FormattedAddress = resource.address.formattedAddress;
                }

                if (!string.IsNullOrWhiteSpace(resource.address.locality))
                {
                    bm.Locality = resource.address.locality;
                }

                if (!string.IsNullOrWhiteSpace(resource.address.postalCode))
                {
                    bm.PostalCode = resource.address.postalCode;
                }

                if (!string.IsNullOrWhiteSpace(resource.address.landmark))
                {
                    bm.Landmark = resource.address.landmark;
                }
            }

            if (!string.IsNullOrWhiteSpace(resource.confidence))
            {
                bm.Confidence = resource.confidence;
            }

            if (!string.IsNullOrWhiteSpace(resource.entityType))
            {
                bm.EntityType = resource.entityType;
            }


            //float latout;
            //if (resource.point != null && resource.point.coordinates.Length > 0 && float.TryParse(resource.point.coordinates[0].ToString(), out latout))
            //    bm.Latitude = latout;

            //float lonout;
            //if (resource.point != null && resource.point.coordinates.Length > 1 && float.TryParse(resource.point.coordinates[1].ToString(), out lonout))
            //    bm.Longitude = lonout;


            //float slatout = 0;
            //if (resource.bbox != null && resource.bbox.Length > 0 && float.TryParse(resource.bbox[0].ToString(), out slatout))
            //    bm.SouthLatitude = slatout;

            //float wlonout;
            //if (resource.bbox != null && resource.bbox.Length > 0 && float.TryParse(resource.bbox[1].ToString(), out wlonout))
            //    bm.WestLongitude = wlonout;

            //float nlatout;
            //if (resource.bbox != null && resource.bbox.Length > 0 && float.TryParse(resource.bbox[2].ToString(), out nlatout))
            //    bm.NorthLatitude = nlatout;

            //float elonout;
            //if (resource.bbox != null && resource.bbox.Length > 0 && float.TryParse(resource.bbox[3].ToString(), out elonout))
            //    bm.EastLongitude = elonout;


            float latout;

            if (resource.point != null && resource.point.coordinates.Length > 0)
            {
                bm.Latitude = resource.point.coordinates[0].ToString();
            }

            float lonout;

            if (resource.point != null && resource.point.coordinates.Length > 1)
            {
                bm.Longitude = resource.point.coordinates[1].ToString();
            }


            float slatout = 0;

            if (resource.bbox != null && resource.bbox.Length > 0)
            {
                bm.SouthLatitude = resource.bbox[0].ToString();
            }

            float wlonout;

            if (resource.bbox != null && resource.bbox.Length > 0)
            {
                bm.WestLongitude = resource.bbox[1].ToString();
            }

            float nlatout;

            if (resource.bbox != null && resource.bbox.Length > 0)
            {
                bm.NorthLatitude = resource.bbox[2].ToString();
            }

            float elonout;

            if (resource.bbox != null && resource.bbox.Length > 0)
            {
                bm.EastLongitude = resource.bbox[3].ToString();
            }


            if (resource.imageWidth > 0)
            {
                bm.ImageWidth = resource.imageWidth;
            }

            if (resource.imageHeight > 0)
            {
                bm.ImageHeight = resource.imageHeight;
            }


            if (resource.zoom > 0)
            {
                bm.ImageZoom = resource.zoom;
            }
        }