Last active
November 25, 2019 11:57
-
-
Save icebeam7/871ad4bd5d103eaef00be962c3f2188f to your computer and use it in GitHub Desktop.
DemoDS: ReverseGeocodeiOS.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.Linq; | |
using System.Threading.Tasks; | |
using Contacts; | |
using CoreLocation; | |
using DemoDS.Models; | |
using DemoDS.Interfaces; | |
[assembly: Xamarin.Forms.Dependency(typeof(DemoDS.iOS.Dependency.ReverseGeocodeiOS))] | |
namespace DemoDS.iOS.Dependency | |
{ | |
public class ReverseGeocodeiOS : IReverseGeocode | |
{ | |
public async Task<LocationAddress>GetLocationAddress(double latitude, double longitude) | |
{ | |
var geoCoder = new CLGeocoder(); | |
var place = new CLLocation(latitude, longitude); | |
var placemarks = await geoCoder.ReverseGeocodeLocationAsync(place); | |
if (placemarks.Any()) | |
{ | |
var placeMark = placemarks.First(); | |
var location = new LocationAddress() | |
{ | |
Name = placeMark.Name, | |
City = placeMark.Locality, | |
Province = placeMark.AdministrativeArea, | |
ZipCode = placeMark.PostalCode, | |
Country = $"{placeMark.Country} ({placeMark.IsoCountryCode})", | |
Address = new CNPostalAddressFormatter().StringFor(placeMark.PostalAddress) | |
}; | |
return location; | |
} | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment