【问题标题】:How can I get Business Address from Google Map Search Activity如何从 Google 地图搜索活动中获取商家地址
【发布时间】:2017-06-25 05:55:03
【问题描述】:

我正在尝试从我的应用程序中启动 Google 地图的搜索活动,以从用户选择的位置获取地址。我可以按照 Google 的指南启动搜索活动,但我无法弄清楚如何为结果启动搜索活动(在这种情况下,用户选择位置作为地址)。

从下面的屏幕,用户可以选择“Peet's Coffee & Tea”作为她的位置,并且控制应该返回到我的应用程序及其地址。

感谢您的宝贵时间,

【问题讨论】:

    标签: android google-maps android-intent google-maps-api-3


    【解决方案1】:

    我可以通过这样做使用 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
            }
        }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-24
      • 1970-01-01
      • 2015-01-08
      • 1970-01-01
      相关资源
      最近更新 更多