summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Maps.WinRT.Tablet/GeocoderBackend.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 13:02:25 -0700
committerJason Smith <jason.smith@xamarin.com>2016-03-22 16:13:41 -0700
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Maps.WinRT.Tablet/GeocoderBackend.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
Initial import
Diffstat (limited to 'Xamarin.Forms.Maps.WinRT.Tablet/GeocoderBackend.cs')
-rw-r--r--Xamarin.Forms.Maps.WinRT.Tablet/GeocoderBackend.cs52
1 files changed, 52 insertions, 0 deletions
diff --git a/Xamarin.Forms.Maps.WinRT.Tablet/GeocoderBackend.cs b/Xamarin.Forms.Maps.WinRT.Tablet/GeocoderBackend.cs
new file mode 100644
index 00000000..565182d4
--- /dev/null
+++ b/Xamarin.Forms.Maps.WinRT.Tablet/GeocoderBackend.cs
@@ -0,0 +1,52 @@
+´╗┐using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Bing.Maps;
+using Bing.Maps.Search;
+
+namespace Xamarin.Forms.Maps.WinRT
+{
+ internal class GeocoderBackend
+ {
+ public static void Register()
+ {
+ Geocoder.GetPositionsForAddressAsyncFunc = GetPositionsForAddress;
+ Geocoder.GetAddressesForPositionFuncAsync = GetAddressesForPositionAsync;
+ }
+
+ static async Task<IEnumerable<string>> GetAddressesForPositionAsync(Position position)
+ {
+ var results = new List<string>();
+ var source = new TaskCompletionSource<IEnumerable<string>>();
+ var requestOptions = new ReverseGeocodeRequestOptions(new Location(position.Latitude, position.Longitude));
+ var response =
+ await
+ new Bing.Maps.Map { Credentials = FormsMaps.AuthenticationToken }.SearchManager.ReverseGeocodeAsync(requestOptions);
+ if (!response.HasError)
+ {
+ foreach (var address in response.LocationData)
+ results.Add(address.Address.FormattedAddress);
+ }
+
+ return results;
+ }
+
+ static async Task<IEnumerable<Position>> GetPositionsForAddress(string s)
+ {
+ var results = new List<Position>();
+
+ if (string.IsNullOrEmpty(s))
+ return results;
+
+ var requestOptions = new GeocodeRequestOptions(s);
+ var response =
+ await new Bing.Maps.Map { Credentials = FormsMaps.AuthenticationToken }.SearchManager.GeocodeAsync(requestOptions);
+ if (!response.HasError)
+ {
+ foreach (var address in response.LocationData)
+ results.Add(new Position(address.Location.Latitude, address.Location.Longitude));
+ }
+ return results;
+ }
+ }
+} \ No newline at end of file