summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Maps.Tizen/GeocoderBackend.cs
blob: dbf93979238abcc7c29313b867cd0a434d60d639 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
´╗┐using System.Collections.Generic;
using System.Threading.Tasks;

namespace Xamarin.Forms.Maps.Tizen
{
	internal class GeocoderBackend
	{
		public static void Register()
		{
			Geocoder.GetPositionsForAddressAsyncFunc = GetPositionsForAddressAsync;
			Geocoder.GetAddressesForPositionFuncAsync = GetAddressesForPositionAsync;
		}

		public static async Task<IEnumerable<Position>> GetPositionsForAddressAsync(string address)
		{
			var request = FormsMaps.MapService.CreateGeocodeRequest(address);
			var positions = new List<Position>();
			foreach (var result in await request.GetResponseAsync())
				positions.Add(new Position(result.Latitude, result.Longitude));
			return positions;
		}

		public static async Task<IEnumerable<string>> GetAddressesForPositionAsync(Position position)
		{
			var request = FormsMaps.MapService.CreateReverseGeocodeRequest(position.Latitude, position.Longitude);
			var addresses = new List<string>();
			foreach (var result in await request.GetResponseAsync())
				addresses.Add(result.Freetext);
			return addresses;
		}
	}
}