2016-04-04 19 views
1

我有一個條目(名爲adressEntry),您在其中編寫地址。我的問題是如何將這個地址變成一個長長的拉特? 迄今爲止,這是我的代碼,但GetAdressesForPositionAsync不允許我輸入變量。Xamarin格式,我怎樣才能得到一個地址的長,拉特?

 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); 

回答

1

如果有一個地址和你想獲得一個位置(對於地址),你應該使用Geocoder.GetPositionsForAddressAsync,不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); 
} 
+0

在日誌中我得到的adressEntry.Text現在(所以ADRESS),我不明白的緯度,經度 – medvedo

+0

明顯的問題:是正確的地址1),2)在一個地區的地理編碼具有信息上? –

+0

@medvedo當然,因爲你正在使用'Debug.WriteLine(theEnteredAddress)' – cubrr

相關問題