- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 Google Place获取地点详情。 Google 提供了不同的方式来实现 Google Place API 以获取地点详细信息。不同的方式如 PlaceAutocompleteFragment 、 PlaceAutocompleteActivity 。如何区分这些以及如何使用 Google place API 实现获取地点详细信息。
最佳答案
首先需要API key并启用 Google Place API 以搜索和获取地点详细信息。将您的 API key 添加到您的应用程序 list 中,需要将 YOUR_API_KEY 替换为您自己的 API key :
<application>
...
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY"/>
</application>
1) PlaceAutocompleteFragment
XML:
<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
/>
Java:
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
/*
* The following code example shows setting an AutocompleteFilter on a PlaceAutocompleteFragment to
* set a filter returning only results with a precise address.
*/
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
.build();
autocompleteFragment.setFilter(typeFilter);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
Log.i(TAG, "Place: " + place.getName());//get place details here
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i(TAG, "An error occurred: " + status);
}
});
输出:
2) PlaceAutocompleteActivity
private void callPlaceAutocompleteActivityIntent() {
try {
Intent intent =
new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
.build(this);
startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
//PLACE_AUTOCOMPLETE_REQUEST_CODE is integer for request code
} catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
// TODO: Handle the error.
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//autocompleteFragment.onActivityResult(requestCode, resultCode, data);
if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Place place = PlaceAutocomplete.getPlace(this, data);
Log.i(TAG, "Place:" + place.toString());
} else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
Status status = PlaceAutocomplete.getStatus(this, data);
Log.i(TAG, status.getStatusMessage());
} else if (resultCode == RESULT_CANCELED) {
}
}
}
输出:
希望对您有所帮助。
编辑:将 requestCode == RESULT_CANCELED
更改为 resultCode == RESULT_CANCELED
关于android - 如何实现 PlaceAutocompleteFragment 和 PlaceAutocompleteActivity 以获取地点详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34416817/
$query = "SELECT Name, CountryCode FROM City ORDER BY Name"; if ($result = $mysqli->query($query)) {
我是 GWT 的新手,我的英语不太好,请见谅。 我需要使用 GWT 创建一个网站。该网站具有层次结构:主要的全局标题和几个按钮。每个按钮都会打开应用程序的新部分,该部分有自己的子选项卡。每个子选项卡都
我正在尝试使用此网站 https://www.timeanddate.com/weather/通过打开如下 URL 使用 BeautifulSoup4 抓取天气数据: quote_page=r"htt
由于我要在移动应用中使用谷歌地图和地点,因此我不希望任何东西减慢应用加载速度。 我发现在边缘网络上,我的应用程序启动速度非常慢。我所有的js都是本地的,所以只有谷歌地图和地点需要很长时间才能加载(如果
我可以通过带有位置 ID 的图形 API 发送查询来返回位置的详细信息,但是我希望实现相反的结果 - 通过发送包含位置名称(城市,州等)。这可能吗? 最佳答案 这在几种不同的方法下是可能的。您可以使用
我正在尝试返回仅限于某种区域的自动完成结果 - the (regions) type collection instructs the Places service to return any res
我有一个多语言网站... 我在 visual studio 中为语言(en + 我的语言)制作了两个文件夹,并为每个文件夹制作了我的网站! 对于一种语言的网站,我有一门类(class)可以根据我的文化
我使用 this向FS请求获取 field 但有些场馆与要求的位置之间的距离超过 500 米。换句话说,ll 和 radius 参数没有像我预期的那样工作。因为我希望拥有所请求区域的所有 field
如果我有一段文本,例如包含一篇加泰罗尼亚语报纸文章,我如何从该文本中找到所有城市? 我一直在查看 python 的 nltk 包,我已经下载了加泰罗尼亚语的语料库 (nltk.corpus.cess_
R 的帮助系统很棒,我喜欢几乎所有函数的帮助页面都包含一个示例,但有时我希望有一种方法可以查看示例代码的结果,而无需复制并粘贴到我当前的 session 中。这对于图形功能来说是双重的。 有没有办法执
我想实现类似的效果,其中引脚被分组在一起,然后当您接近点时用动画分开。当您选择带有地理标记应用的地点时,会在“照片”应用中看到此效果 最佳答案 似乎没有,但有一个第三方库提供了此功能: http://
我在报表生成器/设计模式中看到,有一个“位置”和“位置”属性,可让您设置表格应显示在距顶部或左侧的距离。 我的问题是,有没有办法在同一位置设置 2 个或更多表格(即页面顶部,从顶部开始 0,从左边开始
所以,我有一个 Spring MVC 应用程序,我想要一种方法来确定资源何时不支持特定媒体类型。我正在考虑使用自定义 View 解析器来执行此操作...如果没有一个 View 解析器找到 View 名
有了这个类 import UIKit import CoreLocation private let geometryKey = "geometry" private let locationKey
我正在构建一个系统,其中应该有一个包含组织、位置、部门和用户的数据库。它们按照您的预期连接起来: 每个组织可以包含一个或多个地点 每个地点(建筑物)可以包含一个或多个部门 每个部门工作一名或多名用户
我一直在旧项目上使用 Google place API,但在那些项目中我必须选择一个地方,然后 API 返回给我相关信息地方... 问题是使用相同的 API 我可以请求一个地方,例如 Restaura
这里我有一个脚本,它通过 google places api 显示对象的开放时间。 http://jsbin.com/ATaZEXE/4 现在我想将 .label 类的背景颜色更改为“红色”,如果 p
我正在开发一款 Google map 应用,目标用户可能需要关于特定位置的路线,这些位置只能通过应用中的经纬度获知。 问题是方向需要解析为人类可读的名称,最好是任何位置都可以相对于另一个附近的位置进行
我正在开发一款应用程序,我相信它会对学生有所帮助。我想根据位置包括天气(仅温度)。例如,如果我要从一个城市前往另一个城市,我希望它能针对新城市自动更新。我该怎么做?对于我的第二个问题,我还想将日期(即
我正在使用上游模块来平衡我的网站。出于某种原因,我必须将一些请求重定向到指定的服务器。简而言之:我想将 domain.com 重定向到指定的服务器,domain.com/anything 可以由上游模
我是一名优秀的程序员,十分优秀!