//谷歌地址选择器, PlaceAutocomplete 已经过时被废弃?用不了了。用最新的AutocompleteMigration Guide:-https://developers.google.com/places/android-sdk/client-migration Follows this steps to implement AutoComplete in your project :-There is two way to implement to AutoComplete .1. Using Intent2. Using AutocompleteFragmentIn both case follow these steps:-1. Add this line in build.gradle file//主要是这个dependencies {implementation 'com.google.android.libraries.places:places:1.0.0'}2. Add other dependencies if required in your project.//可以不需要dependencies {implementation 'com.google.android.libraries.places:places-compat:1.0.0'}//可以不需要implementation 'com.google.android.gms:play-services-places:16.0.0'3. // Add an import statement for the client library.import com.google.android.libraries.places.api.Places;// Initialize Places.Places.initialize(getApplicationContext(), apiKey);// Create a new Places client instance.PlacesClient placesClient = Places.createClient(this);----------Now Choose any of the method you want to implement in your project.-----## Using Intent ##//必须要初始化Places,否则运行出错。在application执行。先执行下面的语句,再执行createClient()if (!Places.isInitialized()) {Places.initialize(getApplicationContext(), "YOUR_API_KEY");}...// Set the fields to specify which types of place data to return.List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME);// Start the autocomplete intent.Intent intent = new Autocomplete.IntentBuilder(AutocompleteActivityMode.FULLSCREEN, fields).build(this);startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);and OnActivityResult method-------/*** Override the activity's onActivityResult(), check the request code, and* do something with the returned place data (in this example it's place name and place ID).*/@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {if (resultCode == RESULT_OK) {Place place = Autocomplete.getPlaceFromIntent(data);Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());} else if (resultCode == AutocompleteActivity.RESULT_ERROR) {// TODO: Handle the error.Status status = Autocomplete.getStatusFromIntent(data);Log.i(TAG, status.getStatusMessage());} else if (resultCode == RESULT_CANCELED) {// The user canceled the operation.}}}## Using Fregment ##Initialize this Autocomplete Fregment on .xml file<fragmentandroid:id="@+id/autocomplete_fragment"android:layout_width="match_parent"android:layout_height="wrap_content"android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"/>-------------- and on .class file-------------------------- Initialize Places, passing the application context and your API key.
Initialize the AutocompleteSupportFragment.Call setPlaceFields() to indicate the types of place data that you want to get.
Add a PlaceSelectionListener to do something with the result, as well as handle any errors that might occur.The following example shows adding an autocomplete widget to an activity:/*** Initialize Places. For simplicity, the API key is hard-coded. In a production* environment we recommend using a secure mechanism to manage API keys.*/if (!Places.isInitialized()) {Places.initialize(getApplicationContext(), "YOUR_API_KEY");
}// Initialize the AutocompleteSupportFragment.AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {@Overridepublic void onPlaceSelected(Place place) {// TODO: Get info about the selected place.Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());}@Overridepublic void onError(Status status) {// TODO: Handle the error.Log.i(TAG, "An error occurred: " + status);}
});
详细解决方案
谷歌google place map 地址选择器
热度:27 发布时间:2023-12-17 05:08:34.0
相关解决方案
- google map有关问题
- GWT 报错,能的请进: com.google.gwt.event.shared.UmbrellaException: Exception caught: Se
- google chrome浏览器中 查看框架的源代码,具体是干吗用的,为什么有些网页有这个选项,有些没有
- Google APi可以获取一个地址的所在商圈吗 ,也许百度Map api的java,php调用方法
- 关于 google map 经度和纬度的有关问题
- Google Maps v3 中交通的有关问题
- google.com进不去的时候解决方法。 散分
- 想开发一套基于GPS+GPRS+Google 地图的车辆管理系统,该如何做
- java.net.UnknownHostException: www.google.com.hk,该怎么处理
- google map api key 如何获得
- google、百度的查询速度如此之快,而且并发数这么大,如何做到的
- SQLite.NET 找不到表, Google 了良久了都不行
- javascript取有点网页的html元素的offsetLeft,offsetTop数据不准,比如http://www.google.com.hk/
- Google App Engine 可以筹建IIS开发环境访问吗
- asp.net+google 地图 api
- google 地图不能在form里边显示
- Google 电子凭栏矩形拉框对象一直没找到!
- https google maps不显示,该如何处理
- google map api 动态反向地址解析,该怎么处理
- 搜索引擎(百度,google)接受cookie吗?不是登陆是一般的参数保存。主要是网页收录会不会受影响解决方法
- :小弟我的网站上不少 aspx 页面上都被人强行嵌入了 google 的广告代码,现在用什么方法补救呢?万分感谢
- 类似 google adsense 技术,源代码,本人想开发这样的程序,希望大家多多留言,解决思路
- google checkout 401 erro解决办法
- 编程有时要借助baidu,google,csdn的帮助,正常吗?解决办法
- 散分讨论:是不是 腾讯QQ技术 比 GOOGLE 还牛?解决办法
- google suggest 的有关问题: 输入提醒后, span为什么隐藏不了呢
- GOOGLE,BAIDU对伪装aspx的URL网页收录如何样?和html相比!(顶者有分)
- google 是什么页面?该如何解决
- 有高手用过 Google Checkout吗?解决办法
- 今天面试题目:百度,GOOGLE,搜狐,网易,新浪使用什么数据库?该如何处理