summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Maps.iOS/GeocoderBackend.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Maps.iOS/GeocoderBackend.cs')
-rw-r--r--Xamarin.Forms.Maps.iOS/GeocoderBackend.cs35
1 files changed, 31 insertions, 4 deletions
diff --git a/Xamarin.Forms.Maps.iOS/GeocoderBackend.cs b/Xamarin.Forms.Maps.iOS/GeocoderBackend.cs
index 08ffbbe..e5d1b25 100644
--- a/Xamarin.Forms.Maps.iOS/GeocoderBackend.cs
+++ b/Xamarin.Forms.Maps.iOS/GeocoderBackend.cs
@@ -1,10 +1,22 @@
´╗┐using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using AddressBookUI;
+using Contacts;
using CoreLocation;
+#if __MOBILE__
+using AddressBookUI;
+using CCLGeocoder = CoreLocation.CLGeocoder;
+#else
+using Xamarin.Forms.Maps.MacOS.Extra;
+using CCLGeocoder = Xamarin.Forms.Maps.MacOS.Extra.CLGeocoder;
+#endif
+
+#if __MOBILE__
namespace Xamarin.Forms.Maps.iOS
+#else
+namespace Xamarin.Forms.Maps.MacOS
+#endif
{
internal class GeocoderBackend
{
@@ -17,21 +29,36 @@ namespace Xamarin.Forms.Maps.iOS
static Task<IEnumerable<string>> GetAddressesForPositionAsync(Position position)
{
var location = new CLLocation(position.Latitude, position.Longitude);
- var geocoder = new CLGeocoder();
+ var geocoder = new CCLGeocoder();
var source = new TaskCompletionSource<IEnumerable<string>>();
geocoder.ReverseGeocodeLocation(location, (placemarks, error) =>
{
if (placemarks == null)
placemarks = new CLPlacemark[0];
- IEnumerable<string> addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false));
+ List<string> addresses = new List<string>();
+#if __MOBILE__
+ addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false)).ToList();
+#else
+ foreach (var item in placemarks)
+ {
+ var address = new CNMutablePostalAddress();
+ address.Street = item.AddressDictionary["Street"] == null ? "" : item.AddressDictionary["Street"].ToString();
+ address.State = item.AddressDictionary["State"] == null ? "" : item.AddressDictionary["State"].ToString();
+ address.City = item.AddressDictionary["City"] == null ? "" : item.AddressDictionary["City"].ToString();
+ address.Country = item.AddressDictionary["Country"] == null ? "" : item.AddressDictionary["Country"].ToString();
+ address.PostalCode = item.AddressDictionary["ZIP"] == null ? "" : item.AddressDictionary["ZIP"].ToString();
+ addresses.Add(CNPostalAddressFormatter.GetStringFrom(address, CNPostalAddressFormatterStyle.MailingAddress));
+ }
+#endif
source.SetResult(addresses);
+
});
return source.Task;
}
static Task<IEnumerable<Position>> GetPositionsForAddressAsync(string address)
{
- var geocoder = new CLGeocoder();
+ var geocoder = new CCLGeocoder();
var source = new TaskCompletionSource<IEnumerable<Position>>();
geocoder.GeocodeAddress(address, (placemarks, error) =>
{