public Bitmap DownloadMap(BE.Address address) { string key = "03jhg7NXBfhDqBHCdDPhM5ywhBiMtn5m"; //IGeocoder geocoder = new MapQuestGeocoder(key); //IEnumerable<Geocoding.Address> addresses = await geocoder.GeocodeAsync(address.ToString()); //string latlng = addresses.First().Coordinates.Latitude + "," + addresses.First().Coordinates.Longitude; // location url string url = @"https://www.mapquestapi.com/staticmap/v5/map" + @"?key=" + key + @"&locations=" + address.ToString() + @"&size=500,500@2x"; //daonload static map as Image to filname loction string fileName = Directory.GetCurrentDirectory() + @"\img.jpeg"; using (WebClient wc = new WebClient()) { wc.DownloadFile(url, fileName); } //open and convert image to bitmap Bitmap bitmap; using (Stream bmpStream = File.Open(fileName, FileMode.Open)) { Image image = Image.FromStream(bmpStream); bitmap = new Bitmap(image); } //return image as bitmap return(bitmap); }
/// <summary> /// find distance between to addresses /// </summary> private double Help_Distance(BE.Address first_address, BE.Address seconed_address) { for (int i = 0; i < 3; i++) { try { string origin = first_address.ToString(); //or "תקווה פתח 100 העם אחד "etc. string destination = seconed_address.ToString(); //or "גן רמת 10 בוטינסקי'ז "etc. string KEY = @"5rRMSAOyU11mGgkbAlWk3C1y1y0nT2Gv"; string url = @"https://www.mapquestapi.com/directions/v2/route" + @"?key=" + KEY + @"&from=" + origin + @"&to=" + destination + @"&outFormat=xml" + @"&ambiguities=ignore&routeType=fastest&doReverseGeocode=false" + @"&enhancedNarrative=false&avoidTimedConditions=false"; //request from MapQuest service the distance between the 2 addresses HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader sreader = new StreamReader(dataStream); string responsereader = sreader.ReadToEnd(); response.Close(); //the response is given in an XML format XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(responsereader); if (xmldoc.GetElementsByTagName("statusCode")[0].ChildNodes[0].InnerText == "0") //we have the expected answer { //display the returned distance XmlNodeList distance = xmldoc.GetElementsByTagName("distance"); double distInMiles = Convert.ToDouble(distance[0].ChildNodes[0].InnerText); return(distInMiles * 1.609344); } } catch { Thread.Sleep(500); } } return(BE.Configuration.Defualt_distance); }