public BingMaps SearchByLocationRead() { BingMapsHelper Bing = new BingMapsHelper(ServiceConfiguration["BingMapsKey"].ToString()); BingResult res = Bing.SearchByLocation(this.Query, 1); 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 == null || res.resourceSets[0].resources.Count() < 1) { this.ResultStatus = "OK"; this.ResultMessage = "No results"; } Resource resource = res.resourceSets[0].resources[0]; MapBingMaps(this, resource); this.EstimatedTotal = res.resourceSets[0].estimatedTotal; this.ResultStatus = "OK"; return(this); }
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 BingResult SearchByLocation(string Query, int MaxResults) { string uri = string.Format("{0}/Locations?query={1}&includeNeighborhood=1&incl=ciso2&maxResults={2}&key={3}", BaseUri, Query, MaxResults, BingMapsKey); BingResult bing = null; bing = GetBingMapsData(uri); return(bing); }
public BingResult GetMapImageMetadataByLocation(string Location, int Zoom, string MapStyle, int Width, int Height, string MapLayer, List <PushPin> Pins, 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); } return(GetMapImageMetadata(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, 1))); }
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); }
//string base64 = string.Empty; // if(MapMetadata != 1) // { // bing = new BingResult(); // base64 = DownloadFileToBase64(uri); // bing.imageBase64 = base64; // } //bing = GenerateCoordinatesImage(Latitude, Longitude, Zoom, MapStyle, Width, Height, MapStyle, Pins, ImageFormat, DeclutterPins, 1); //bing.resourceSets[0].resources[0].imageBase64 = base64; private BingResult GetBingMapsData(string uri) { BingResult res = null; try { using (WebClient client = new WebClient()) { string result = client.DownloadString(uri); res = Newtonsoft.Json.JsonConvert.DeserializeObject <BingResult>(result); } } catch (Exception ex) { throw; } return(res); }
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 BingResult SearchByPoint(string Latitude, string Longitude, string IncludeEntityTypes) { BingResult bing = null; string uri = string.Format("{0}/Locations/{1},{2}?o=json&includeNeighborhood=1&incl=ciso2&key={3}", BaseUri, Latitude, Longitude, BingMapsKey); if (!string.IsNullOrWhiteSpace(IncludeEntityTypes)) { //Address //Neighborhood //PopulatedPlace //Postcode1 //AdminDivision1 //AdminDivision2 //CountryRegion uri += uri + "&includeEntityTypes=" + IncludeEntityTypes; } bing = GetBingMapsData(uri); return(bing); }
public BingMaps SearchByLatLonRead() { if (string.IsNullOrWhiteSpace(this.IncludeEntityTypes)) { this.IncludeEntityTypes = ""; } BingMapsHelper Bing = new BingMapsHelper(ServiceConfiguration["BingMapsKey"].ToString()); //decimal.Round(decimal.Parse(this.Lat), 5, MidpointRounding.AwayFromZero).ToString(); //decimal.Parse(this.Lat).ToString("#.#####"); BingResult res = Bing.SearchByPoint(decimal.Parse(this.Lat).ToString(_decimalFormat), decimal.Parse(this.Lon).ToString(_decimalFormat), this.IncludeEntityTypes); // BingResult res = Bing.SearchByPoint(this.Lat.ToString(), this.Lon.ToString(), this.IncludeEntityTypes); 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 == null || res.resourceSets[0].resources.Count() < 1) { this.ResultStatus = "OK"; this.ResultMessage = "No results"; } Resource resource = res.resourceSets[0].resources[0]; MapBingMaps(this, resource); this.EstimatedTotal = res.resourceSets[0].estimatedTotal; this.ResultStatus = "OK"; return(this); }