我正在尝试从我的应用程序启动Google Map的搜索活动,以从用户选择的位置获取地址。我可以根据Google'启动搜索活动。准则,但我无法弄清楚如何为结果启动搜索活动(在这种情况下,用户选择的位置作为地址)。
从屏幕下方,用户可以选择" Peet's Coffee&茶"因为她的位置和控制应该返回我的应用程序及其地址。
感谢您的时间,
答案 0 :(得分:0)
我可以通过使用Google PlacePicker API来实现这一目标
try
{
PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
Intent intent = intentBuilder.build(getActivity());
// Start the Intent by requesting a result, identified by a request code.
startActivityForResult(intent, ET_PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e)
{
GooglePlayServicesUtil
.getErrorDialog(e.getConnectionStatusCode(), getActivity(), 0);
} catch (GooglePlayServicesNotAvailableException e)
{
Toast.makeText(getActivity(), "Google Play Services is not available.",
Toast.LENGTH_LONG)
.show();
}
和ActivityResult() -
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == ET_PLACE_PICKER_REQUEST)
{
if (resultCode == Activity.RESULT_OK)
{
final Place place = PlacePicker.getPlace(getContext(), data);
final CharSequence name = place.getName();
final CharSequence address = place.getAddress();
final String placeId = place.getId();
//Your Code
}
}}