I have an entry (named adressEntry) where you write an adress. My question is how do I turn that adress into a long, lat? This is my code so far, but the GetAdressesForPositionAsync does not let me enter the variable.
var theEnteredAdress = adressEntry.Text;
Geocoder gc = new Geocoder ();
Task<IEnumerable<Position>> result =
gc.GetAddressesForPositionAsync (theEnteredAdress); //cannot enter the variable value here. Cannot convert string expression to type: Xamarin.Forms.Maps.Position
System.Diagnostics.Debug.WriteLine (theEnteredAdress);
答案 0 :(得分:1)
If you have an address and you want to get a position (for the address), you should be using Geocoder.GetPositionsForAddressAsync
, not Geocoder.GetAddressesForPositionAsync
.
var theEnteredAdress = adressEntry.Text;
Geocoder gc = new Geocoder();
IEnumerable<Position> result =
await gc.GetPositionsForAddressAsync(theEnteredAdress);
foreach (Position pos in result)
{
System.Diagnostics.Debug.WriteLine("Lat: {0}, Lng: {1}", pos.Latitude, pos.Longitude);
}