Last active
November 25, 2019 13:21
-
-
Save icebeam7/03df8821e153f5abf460ab40023155e4 to your computer and use it in GitHub Desktop.
DemoDS: ReverseGeocodeUWP.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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