public static async Task <IList <double[]> > GetCoordonateFromName(IList <string> address) { var location = new Geocoder(Application.Context); IList <double[]> result = new List <double[]>(); foreach (var item in address) { IList <Address> resultServer = new List <Address>(); try { resultServer = await location.GetFromLocationNameAsync(item, 1); } catch (Exception ex) { Console.WriteLine(ex.Message); } if (resultServer.Count <= 0) { continue; } var firstOrDefault = resultServer.FirstOrDefault(); if (firstOrDefault != null) { result.Add(new[] { firstOrDefault.Latitude, firstOrDefault.Longitude }); } } location.Dispose(); return(result); }
public static async Task <double[]> GetCoordonateFromName(string address) { var location = new Geocoder(Application.Context); IList <Address> resultServer = new List <Address>(); try { resultServer = await location.GetFromLocationNameAsync(address, 1); } catch (Exception ex) { Console.WriteLine(ex.Message); } var firstOrDefault = resultServer.FirstOrDefault(); if (firstOrDefault != null) { return resultServer.Count > 0 ? new[] { firstOrDefault.Latitude, firstOrDefault.Longitude } } : default(double[]); location.Dispose(); return(default(double[])); }