我想从Google's Places Api与Xamarin Android的基本自动完成功能。Xamarin Android谷歌地方Api自动完成破
我使用的是Xamarin的Google Play Services - Location库版本25.0.0.0。
我已经成功地得到一个查询返回结果的点,同时下面this example code
这是我使用测试代码的片段
public class PlaceAutocomplete: BaseFragment, IGoogleApiClientOnConnectionFailedListener {
IGoogleApiClient client;
public override void OnCreate(Bundle savedInstanceState) {
base.OnCreate(savedInstanceState);
client = new GoogleApiClientBuilder(Activity)
.EnableAutoManage(Activity as BaseFragmentActivity, 0, this)
.AddOnConnectionFailedListener(OnConnectionFailed)
.AddApi(Places.GEO_DATA_API)
.Build();
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Places.GeoDataApi.GetAutocompletePredictions(client, "cul",
new LatLngBounds(new LatLng(33.515071, -118.796427), new LatLng(34.435985, -117.127371)), null)
.SetResultCallback<AutocompletePredictionBuffer>(AutocompleteResult);
return base.OnCreateView(inflater, container, savedInstanceState);
}
public void AutocompleteResult(AutocompletePredictionBuffer buffer) {
if(!buffer.Status.IsSuccess) {
Toast.MakeText(Activity, buffer.Status.StatusMessage, ToastLength.Long).Show();
return;
}
var a = new List<IAutocompletePrediction>();
for(var i = 0; i < buffer.Count; i++) {
var item = buffer.Get(i);
if(item is IAutocompletePrediction) {
a.Add((IAutocompletePrediction) item);
} else {
//all the results go in here
}
}
Toast.MakeText(Activity, a.Count.ToString(), ToastLength.Long).Show();
}
public void OnConnectionFailed(ConnectionResult result) {
}
}
有5返回的结果从GetAutocompletePredictions方法,但他们的所有类型名为com.google.android.gms.location.places.internal.zzb,不能转换为IAutocompletePrediction,我没有找到任何方式来使用它们。
我做错了什么或者Xamarin的Google Play图书馆的这部分功能没有完全实现?
如果你的要求是从一个地方API只自动完成那么这可能对您有所帮助,下载使用REST请求http://appliedcodelog.blogspot.in/2015/05/google-place-api-with-autocomplete-in.html – Suchith