private static async Task <string> GetCity(Geoposition position) { var culture = new CultureInfo("en-US"); // Ключ доступа к BingMaps API. const string bingApiKey = "AgDeteITUMycomwytDapPxEtYzVsXGgl7rjygsBaEiZKrNS7mvIGBBc_M3J4ky-8"; var serializer = new DataContractJsonSerializer(typeof(Response)); // Отправляем запрос к API, в качестве параметров указывая координаты устройства и ключ. var response = await ViewModelServices.GetHttpResponseAsync( String.Format(culture, "http://dev.virtualearth.net/REST/v1/Locations/{0},{1}?o=json&key={2}", position.Coordinate.Point.Position.Latitude, position.Coordinate.Point.Position.Longitude, bingApiKey)); Response restApiResponse; try { restApiResponse = serializer.ReadObject(response) as Response; } catch (SerializationException) { throw; } // Покопавшись в документации к API, выясняем, где в ответе найти город. Возвращаем его. return(restApiResponse.ResourceSets[0].Resources[0].Address.AdminDistrict2); }
protected async Task <TViewModel> Bind <TViewModel>(object settings) where TViewModel : IViewModel, new() { var result = new TViewModel(); if (settings != null) { await ViewModelServices.CopyData(settings, result); } return(result); }
public async Task BindModelAsync(ModelBindingContext bindingContext) { var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName).FirstValue; bindingContext.Result = ModelBindingResult.Success(await ViewModelServices.Convert(value.OrEmpty(), bindingContext.ModelType)); }