• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AutocompletePrediction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.android.gms.location.places.AutocompletePrediction的典型用法代码示例。如果您正苦于以下问题:Java AutocompletePrediction类的具体用法?Java AutocompletePrediction怎么用?Java AutocompletePrediction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AutocompletePrediction类属于com.google.android.gms.location.places包,在下文中一共展示了AutocompletePrediction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getView

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = super.getView(position, convertView, parent);

    // Sets the primary and secondary text for a row.
    // Note that getPrimaryText() and getSecondaryText() return a CharSequence that may contain
    // styling based on the given CharacterStyle.

    AutocompletePrediction item = getItem(position);

    TextView textView1 = (TextView) row.findViewById(android.R.id.text1);
    TextView textView2 = (TextView) row.findViewById(android.R.id.text2);
    textView1.setText(item.getPrimaryText(STYLE_BOLD));
    textView2.setText(item.getSecondaryText(STYLE_BOLD));

    return row;
}
 
开发者ID:Mun0n,项目名称:MADBike,代码行数:18,代码来源:PlaceAutocompleteAdapter.java


示例2: getAutocomplete

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
    if (mGoogleApiClient.isConnected()) {

        PendingResult<AutocompletePredictionBuffer> results =
                Places.GeoDataApi
                        .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                mBounds, mPlaceFilter);

        AutocompletePredictionBuffer autocompletePredictions = results
                .await(60, TimeUnit.SECONDS);

        final Status status = autocompletePredictions.getStatus();
        if (!status.isSuccess()) {
            Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
                    Toast.LENGTH_SHORT).show();
            autocompletePredictions.release();
            return null;
        }
        return DataBufferUtils.freezeAndClose(autocompletePredictions);
    }
    return null;
}
 
开发者ID:Mun0n,项目名称:MADBike,代码行数:23,代码来源:PlaceAutocompleteAdapter.java


示例3: getAutocompleteResults

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
public Observable<PlacePrediction> getAutocompleteResults(final GoogleApiClient mGoogleApiClient, final String query, final LatLngBounds bounds) {
    return Observable.create(new Observable.OnSubscribe<PlacePrediction>() {
        @Override
        public void call(Subscriber<? super PlacePrediction> subscriber) {

            PendingResult<AutocompletePredictionBuffer> results =
                    Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, query,
                            bounds, null);

            AutocompletePredictionBuffer autocompletePredictions = results
                    .await(60, TimeUnit.SECONDS);

            final Status status = autocompletePredictions.getStatus();
            if (!status.isSuccess()) {
                autocompletePredictions.release();
                subscriber.onError(null);
            } else {
                for (AutocompletePrediction autocompletePrediction : autocompletePredictions) {
                    subscriber.onNext(
                            new PlacePrediction(
                                    autocompletePrediction.getPlaceId(),
                                    autocompletePrediction.getDescription()
                            ));
                }
                autocompletePredictions.release();
                subscriber.onCompleted();
            }
        }
    });
}
 
开发者ID:sathishmscict,项目名称:Pickr,代码行数:31,代码来源:DataManager.java


示例4: getAutocomplete

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
  if (mGoogleApiClient.isConnected()) {
    PendingResult<AutocompletePredictionBuffer> results =
        Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
            mBounds, mPlaceFilter);

    AutocompletePredictionBuffer autocompletePredictions = results.await(60, TimeUnit.SECONDS);

    final Status status = autocompletePredictions.getStatus();
    if (!status.isSuccess()) {
      Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
          Toast.LENGTH_SHORT).show();
      autocompletePredictions.release();
      return null;
    }

    return DataBufferUtils.freezeAndClose(autocompletePredictions);
  }
  return null;
}
 
开发者ID:jotaramirez90,项目名称:AutocompleteLocation,代码行数:21,代码来源:AutoCompleteAdapter.java


示例5: getAutocomplete

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
	if (mGoogleApiClient.isConnected()) {
		PendingResult<AutocompletePredictionBuffer> results =
                  Places.GeoDataApi
			.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
										mBounds, mPlaceFilter);
 				AutocompletePredictionBuffer autocompletePredictions = results
                  .await(60, TimeUnit.SECONDS);
				final Status status = autocompletePredictions.getStatus();
		if (!status.isSuccess()) {
			if (callback != null) callback.onSuggestFail(status);
			autocompletePredictions.release();
			return null;
		}
			return DataBufferUtils.freezeAndClose(autocompletePredictions);
	}
		return null;
}
 
开发者ID:agusibrahim,项目名称:go-jay,代码行数:19,代码来源:PlaceAutoCompleteHelper.java


示例6: getView

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = super.getView(position, convertView, parent);

    // Sets the primary and secondary text for a row.
    // Note that getPrimaryText() and getSecondaryText() return a CharSequence that may contain
    // styling based on the given CharacterStyle.

    AutocompletePrediction item = getItem(position);

    try{
        TextView textView1 = (TextView) row.findViewById(android.R.id.text1);
        TextView textView2 = (TextView) row.findViewById(android.R.id.text2);
        textView1.setText(item.getPrimaryText(STYLE_BOLD));
        textView2.setText(item.getSecondaryText(STYLE_BOLD));
    } catch (Exception e){
        e.printStackTrace();
    }

    return row;
}
 
开发者ID:blessingoraz,项目名称:Akwukwo,代码行数:22,代码来源:PlaceAutocompleteAdapter.java


示例7: onItemClick

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
    /*
     Retrieve the place ID of the selected item from the Adapter.
     The adapter stores each Place suggestion in a AutocompletePrediction from which we
     read the place ID and title.
      */
    final AutocompletePrediction item = mAdapter.getItem (position);
    final String placeId = item.getPlaceId ();
    final CharSequence primaryText = item.getPrimaryText (null);
    Log.i("", "Autocomplete item selected: " + primaryText);

    /*
     Issue a request to the Places Geo Data API to retrieve a Place object with additional
     details about the place.
      */
    PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
            .getPlaceById (mGoogleApiClient, placeId);
    placeResult.setResultCallback (mUpdatePlaceDetailsCallback);

    Log.i("", "Called getPlaceById to get Place details for " + placeId);
    mSearchLocation.setThreshold(1000);
}
 
开发者ID:blessingoraz,项目名称:Akwukwo,代码行数:24,代码来源:SearchLocationActivity.java


示例8: onItemClick

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    /*
     Retrieve the place ID of the selected item from the Adapter.
     The adapter stores each Place suggestion in a AutocompletePrediction from which we
     read the place ID and title.
      */
    final AutocompletePrediction item = mAdapter.getItem(position);
    final String placeId = item.getPlaceId();
    final CharSequence primaryText = item.getPrimaryText(null);

    Log.i(TAG, "Autocomplete item selected: " + primaryText);

    /*
     Issue a request to the Places Geo Data API to retrieve a Place object with additional
     details about the place.
      */
    PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
            .getPlaceById(mGoogleApiClient, placeId);
    placeResult.setResultCallback(mUpdatePlaceDetailsCallback);

    Toast.makeText(getApplicationContext(), "Clicked: " + primaryText,
            Toast.LENGTH_SHORT).show();
    Log.i(TAG, "Called getPlaceById to get Place details for " + placeId);
}
 
开发者ID:David-Hackro,项目名称:ExamplesAndroid,代码行数:26,代码来源:MainActivity.java


示例9: updateToOfflineHistory

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
private void updateToOfflineHistory() {

        FileOutputStream outputStream;

        try {
            // delete file content
            PrintWriter writer = new PrintWriter(historyFile);
            writer.print("");
            writer.close();

            outputStream = appContext.openFileOutput(historyFileName, Context.MODE_APPEND); //todo MODE_PRIVATE ?
            for (AutocompletePrediction prediction : onlineHistory){
                outputStream.write(prediction.getPlaceId().concat("\n").getBytes());
            }
            outputStream.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
开发者ID:nogalavi,项目名称:Bikeable,代码行数:21,代码来源:SearchHistoryCollector.java


示例10: showOnlyFixedResults

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
private void showOnlyFixedResults() {
    PlaceAutocompleteAdapter currAdapter = (PlaceAutocompleteAdapter) currView.getAdapter();
    ArrayList<AutocompletePrediction> fixedResults = new ArrayList();
    fixedResults.addAll(currAdapter.getFixedResults());
    if (searchHistoryCollector != null && !searchHistoryCollector.getOnlineHistory().isEmpty()){
        fixedResults.addAll(searchHistoryCollector.getOnlineHistory());
    }

    currAdapter.setResultsList(fixedResults);
    currView.getHandler().postDelayed(new Runnable() {
        @Override
        public void run() {
            currView.showDropDown();
        }
    }, 500);
}
 
开发者ID:nogalavi,项目名称:Bikeable,代码行数:17,代码来源:ClearableAutoCompleteTextView.java


示例11: onItemClick

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    /*
     Retrieve the place ID of the selected item from the Adapter.
     The adapter stores each Place suggestion in a AutocompletePrediction from which we
     read the place ID and title.
      */
    final AutocompletePrediction item = mAdapter.getItem(position);
    final String placeId = item.getPlaceId();
    final CharSequence primaryText = item.getPrimaryText(null);

    Log.i(TAG, "Autocomplete item selected: " + primaryText);

    /*
     Issue a request to the Places Geo Data Client to retrieve a Place object with
     additional details about the place.
      */
    Task<PlaceBufferResponse> placeResult = mGeoDataClient.getPlaceById(placeId);
    placeResult.addOnCompleteListener(mUpdatePlaceDetailsCallback);

    Toast.makeText(getApplicationContext(), "Clicked: " + primaryText,
            Toast.LENGTH_SHORT).show();
    Log.i(TAG, "Called getPlaceById to get Place details for " + placeId);
}
 
开发者ID:googlesamples,项目名称:android-play-places,代码行数:25,代码来源:MainActivity.java


示例12: performQuery

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
void performQuery(final String query) {
    Timber.d("performQuery: %s", query);

    placeEngine.queryAutocompletion(query)
            .subscribe(new Subscriber<Iterable<AutocompletePrediction>>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {
                    Timber.w(e, "failed to queryAutocompletion queryAutocompletion for: %s", query);
                }

                @Override
                public void onNext(Iterable<AutocompletePrediction> predictions) {
                    clear();
                    addAll(convertToSpannedList(predictions));
                }
            });

}
 
开发者ID:gfx,项目名称:Android-HankeiN,代码行数:24,代码来源:AddressAutocompleAdapter.java


示例13: onItemClick

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    AnalyticsManager.getInstance().trackSearch();
    final AutocompletePrediction item = mAdapter.getItem(position);
    final String placeId = item.getPlaceId();
    final CharSequence primaryText = item.getPrimaryText(null);
    PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
            .getPlaceById(mGoogleApiClient, placeId);
    placeResult.setResultCallback(mUpdatePlaceDetailsCallback);
}
 
开发者ID:Mun0n,项目名称:MADBike,代码行数:11,代码来源:SearchActivity.java


示例14: onItemClick

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  UIUtils.hideKeyboard(AutoCompleteLocation.this.getContext(), AutoCompleteLocation.this);
  final AutocompletePrediction item = mAutoCompleteAdapter.getItem(position);
  if (item != null) {
    final String placeId = item.getPlaceId();
    PendingResult<PlaceBuffer> placeResult =
        Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId);
    placeResult.setResultCallback(mUpdatePlaceDetailsCallback);
  }
}
 
开发者ID:jotaramirez90,项目名称:AutocompleteLocation,代码行数:11,代码来源:AutoCompleteLocation.java


示例15: getView

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override public View getView(int position, View convertView, ViewGroup parent) {
  View row = super.getView(position, convertView, parent);
  AutocompletePrediction item = getItem(position);
  TextView textView1 = (TextView) row.findViewById(android.R.id.text1);
  TextView textView2 = (TextView) row.findViewById(android.R.id.text2);
  textView1.setText(item.getPrimaryText(STYLE_BOLD));
  textView2.setText(item.getSecondaryText(STYLE_BOLD));

  return row;
}
 
开发者ID:jotaramirez90,项目名称:AutocompleteLocation,代码行数:11,代码来源:AutoCompleteAdapter.java


示例16: onItemClick

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
	final AutocompletePrediction item = mAdapter.getItem(position);
          final String placeId = item.getPlaceId();
	PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
		.getPlaceById(mGoogleApiClient, placeId);
          placeResult.setResultCallback(mUpdatePlaceDetailsCallback);
}
 
开发者ID:agusibrahim,项目名称:go-jay,代码行数:9,代码来源:PlaceAutoCompleteHelper.java


示例17: getView

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	View row = super.getView(position, convertView, parent);
	AutocompletePrediction item = getItem(position);
		TextView textView1 = (TextView) row.findViewById(R.id.place1);
	TextView textView2 = (TextView) row.findViewById(R.id.place2);
	ImageView img=(ImageView) row.findViewById(R.id.itemplaceImageView1);
	textView1.setText(item.getPrimaryText(STYLE_BOLD));
	textView2.setText(item.getFullText(STYLE_BOLD));
	img.setColorFilter(android.graphics.Color.GRAY);
			return row;
}
 
开发者ID:agusibrahim,项目名称:go-jay,代码行数:13,代码来源:PlaceAutoCompleteHelper.java


示例18: getPredictions

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
private ArrayList<PlaceAutocomplete> getPredictions(CharSequence constraint) {
    if (mGoogleApiClient != null) {
        Log.i(TAG, "Executing autocomplete query for: " + constraint);
        PendingResult<AutocompletePredictionBuffer> results =
                Places.GeoDataApi
                        .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                mBounds, mPlaceFilter);
        // Wait for predictions, set the timeout.
        AutocompletePredictionBuffer autocompletePredictions = results
                .await(60, TimeUnit.SECONDS);
        final Status status = autocompletePredictions.getStatus();
        if (!status.isSuccess()) {
            Toast.makeText(getContext(), "We recommend using internet for better accuracy of the location! ", Toast.LENGTH_SHORT).show();

            Log.e(TAG, "Error getting place predictions: " + status.toString());
            autocompletePredictions.release();
            return null;
        }

        Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
                + " predictions.");
        Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
        ArrayList resultList = new ArrayList<>(autocompletePredictions.getCount());
        while (iterator.hasNext()) {
            AutocompletePrediction prediction = iterator.next();
            resultList.add(new PlaceAutocomplete(prediction.getPlaceId(),
                    prediction.getFullText(null)));
        }
        // Buffer release
        autocompletePredictions.release();
        return resultList;
    }
    Log.e(TAG, "Google API client is not connected.");
    return null;
}
 
开发者ID:alewin,项目名称:moneytracking,代码行数:36,代码来源:PlaceAdapter.java


示例19: getAutoComplete

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
/**
 * Method to call API for each user input
 * @param constraint User input character string
 * @return ArrayList containing suggestion results
 */
private ArrayList<PlaceAutoComplete> getAutoComplete(CharSequence constraint){
    if(mGoogleApiClient.isConnected()){
        //Making a query and fetching result in a pendingResult

        PendingResult<AutocompletePredictionBuffer> results= Places.GeoDataApi
                .getAutocompletePredictions(mGoogleApiClient,constraint.toString(),mBounds,mPlaceFilter);

        //Block and wait for 60s for a result
        AutocompletePredictionBuffer autocompletePredictions=results.await(60, TimeUnit.SECONDS);

        final Status status=autocompletePredictions.getStatus();

        // Confirm that the query completed successfully, otherwise return null
        if(!status.isSuccess()){
            Log.e(TAG, "Error getting autocomplete prediction API call: " + status.toString());
            autocompletePredictions.release();
            return null;
        }

        Log.i(TAG, "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).

        Iterator<AutocompletePrediction> iterator=autocompletePredictions.iterator();
        ArrayList resultList=new ArrayList<>(autocompletePredictions.getCount());
        while(iterator.hasNext()){
            AutocompletePrediction prediction=iterator.next();
            resultList.add(new PlaceAutoComplete(prediction.getPlaceId(),prediction.getPrimaryText(null),prediction.getSecondaryText(null)));
        }
        autocompletePredictions.release();
        return resultList;
    }else{
        Log.e(TAG,"GoogleApiClient Not Connected");
        return  null;
    }
}
 
开发者ID:pmathew92,项目名称:MapsWithPlacesAutoComplete,代码行数:44,代码来源:AutoCompleteAdapter.java


示例20: initPlaceId

import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public Observable<Toilet> initPlaceId(Location currentLocation, Toilet toilet) {
    String requestString = (toilet.getCity() + ", " + toilet.getAddress()).replace(", б/н", "");
    if (toilet.getLatitude() != 0) {
        return Observable.just(toilet);
    }
    return locationProvider.getPlaceAutocompletePredictions(requestString, null, null)
            .map(autocompletePredictions -> {
                String placeId = null;
                for (AutocompletePrediction prediction : autocompletePredictions) {
                    if (prediction.getSecondaryText(null).toString().contains(toilet.getCity() + ",")) {
                        placeId = prediction.getPlaceId();
                        break;
                    } else {
                        Timber.e("Location prediction fail: %s", prediction.getSecondaryText(null));
                    }
                }
                toilet.setPlaceId(placeId);
                return toilet;
            })
            .flatMap(toilet1 -> toilet.getPlaceId() == null ? Observable.just(toilet1) : locationProvider.getPlaceById(toilet1.getPlaceId()).flatMap(places -> {
                LatLng latLng = places.get(0).getLatLng();
                if (latLng != null) {
                    toilet1.setLatitude(latLng.latitude);
                    toilet1.setLongitude(latLng.longitude);
                }
                return Observable.just(toilet1);
            }))
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread());
}
 
开发者ID:lvanyal,项目名称:directly,代码行数:32,代码来源:LocationRepositoryImpl.java



注:本文中的com.google.android.gms.location.places.AutocompletePrediction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Pass类代码示例发布时间:2022-05-21
下一篇:
Java VKError类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap