public override void Execute(object parameter)
		{
			if (string.IsNullOrWhiteSpace(queryModel.Address))
				return;

			var url = "http://dev.virtualearth.net/REST/v1/Locations?q=" + Uri.EscapeUriString(queryModel.Address) +
					  "&key=Anlj2YMQu676uXmSj1QTSni66f8DjuBGToZ21t5z9E__lL8IHRhFP8LtF7umitL6";
			var webRequest = WebRequest.Create(new Uri(url, UriKind.Absolute));
			webRequest.GetResponseAsync().ContinueOnSuccessInTheUIThread(doc =>
			{
				RavenJObject jsonData;
				using (var stream = doc.GetResponseStream())
				using (var reader = new StreamReader(stream))
				using (var jsonReader = new JsonTextReader(reader))
					jsonData = RavenJObject.Load(jsonReader);

				var set = jsonData["resourceSets"];

				var item = set.Values().First().Values().ToList()[1].Values().ToList();
				if (item.Count == 0)
				{
					ApplicationModel.Current.AddInfoNotification("Could not calculate the given address");
					return;
				}

				var result = item.First().SelectToken("point").SelectToken("coordinates").Values().ToList();

				if (result != null)
				{
					var latitude = double.Parse(result[0].ToString());
					var longitude = double.Parse(result[1].ToString());
					var addressData = new AddressData { Address = queryModel.Address, Latitude = latitude, Longitude = longitude };
					queryModel.UpdateResultsFromCalculate(addressData);
				}

			}).Catch();
		}
		public override void Execute(object parameter)
		{
			var url = "http://where.yahooapis.com/geocode?flags=JC&q=" + queryModel.Address;
			var webRequest = WebRequest.Create(new Uri(url, UriKind.Absolute));
			webRequest.GetResponseAsync().ContinueOnSuccessInTheUIThread(doc =>
			{
				RavenJObject jsonData;
				using (var stream = doc.GetResponseStream())
				{
					jsonData = RavenJObject.Load(new JsonTextReader(new StreamReader(stream)));
				}

				var result = jsonData["ResultSet"].SelectToken("Results").Values().FirstOrDefault();

				if (result != null)
				{
					var latitude = double.Parse(result.Value<string>("latitude"));
					var longitude = double.Parse(result.Value<string>("longitude"));
					var addressData = new AddressData { Address = queryModel.Address, Latitude = latitude, Longitude = longitude };
					queryModel.UpdateResultsFromCalculate(addressData);
				}

			}).Catch();
		}
Пример #3
0
		public void UpdateResultsFromCalculate(AddressData addressData)
		{
			latitude = addressData.Latitude;
			longitude = addressData.Longitude;

			var addresses = PerDatabaseState.RecentAddresses.ContainsKey(IndexName) ? PerDatabaseState.RecentAddresses[IndexName] : new Dictionary<string, AddressData>();

			addresses[addressData.Address] = addressData;

			PerDatabaseState.RecentAddresses[IndexName] = addresses;

			OnPropertyChanged(() => Latitude);
			OnPropertyChanged(() => Longitude);
		}