Google自动填充位置

时间:2015-08-14 16:54:21

标签: android google-maps autocomplete google-api

我正在制作一个Android应用程序,其中我有一个AutocompleteTextview,我将输入地名和建议现在出来我现在使用谷歌地图api这个我的代码现在下面给出我的代码没有运行可以有人请告诉我,我做错了。

PendingResult results = Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient , null, BOUNDS_GREATER_SYDNEY, null);
            Log.d("hii", "3");
            AutocompletePredictionBuffer autocompletePredictions = (AutocompletePredictionBuffer) results
                    .await(60, TimeUnit.SECONDS);
            Log.d("hii", "4");
            final Status status = autocompletePredictions.getStatus();
            if (!status.isSuccess()) {
                Log.d("hii", "5");
  //              Toast.makeText(Location_AutoComplete.this, "Error contacting API: " + status.toString(),
  //                      Toast.LENGTH_SHORT).show();
                Log.e("hii", "Error getting autocomplete prediction API call: " + status.toString());
                autocompletePredictions.release();
            }
            Log.d("hii", "6");
            Log.i("hii", "Query completed. Received " + autocompletePredictions.getCount()
                    + " predictions.");

            // Copy the results into our own data structure, because we can't hold onto the buffer.
            // AutocompletePrediction objects encapsulate the API response (place ID and description).
            int i = 0;
            Log.d("hii", "7");

            String[] locsss = new String[autocompletePredictions.getCount()];
            Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
            ArrayList resultList = new ArrayList<>(autocompletePredictions.getCount());
            while (iterator.hasNext()) {
                Log.d("hii", "8");
                AutocompletePrediction prediction = iterator.next();
                // Get the details of this prediction and copy it into a new PlaceAutocomplete object.
                Log.d("hii", "location "+prediction.getPlaceId());
                locsss[i] = prediction.getPlaceId();
  //              resultList.add(new PlaceAutocomplete(prediction.getPlaceId(),
  //                      prediction.getDescription()));
                i++;
            }
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(Location_AutoComplete.this, android.R.layout.simple_list_item_1, locsss);
            mAutocompleteView.setAdapter(adapter);
            mAutocompleteView.setOnItemClickListener(
                    new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            //
                        }
                    }
            );

0 个答案:

没有答案