Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Last active November 25, 2019 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icebeam7/03df8821e153f5abf460ab40023155e4 to your computer and use it in GitHub Desktop.
Save icebeam7/03df8821e153f5abf460ab40023155e4 to your computer and use it in GitHub Desktop.
DemoDS: ReverseGeocodeUWP.cs
using System;
using System.Linq;
using System.Threading.Tasks;
using Windows.Services.Maps;
using Windows.Devices.Geolocation;
using DemoDS.Models;
using DemoDS.Interfaces;
[assembly: Xamarin.Forms.Dependency(typeof(DemoDS.UWP.Dependency.ReverseGeocodeUWP))]
namespace DemoDS.UWP.Dependency
{
public class ReverseGeocodeUWP : IReverseGeocode
{
public async Task<LocationAddress> GetLocationAddress(double latitude, double longitude)
{
MapService.ServiceToken = "create-a-key-at-www.bingmapsportal.com";
var geoPosition = new BasicGeoposition()
{
Latitude = latitude,
Longitude = longitude
};
var geoPoint = new Geopoint(geoPosition);
var place = await MapLocationFinder.FindLocationsAtAsync(geoPoint);
if (place.Status == MapLocationFinderStatus.Success)
{
var mapLocation = place.Locations.First();
var mapAddress = mapLocation.Address;
var location = new LocationAddress()
{
Name = mapLocation.DisplayName,
City = mapAddress.Town,
Province = mapAddress.Region,
ZipCode = mapAddress.PostCode,
Country = $"{mapAddress.Country} ({mapAddress.CountryCode})",
Address = $"{mapAddress.Street} {mapAddress.StreetNumber}",
};
return location;
}
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment