【问题标题】:How do I open google maps app on tapping an address?如何在点击地址时打开谷歌地图应用程序?
【发布时间】:2019-08-16 03:24:42
【问题描述】:

我的应用中有一个地址参数,例如“921 Beverly Hills, california, CA-09001” 点击这个后,我希望谷歌地图打开并显示这个确切地址的注释。我怎么做? 有什么线索吗?

【问题讨论】:

    标签: android android-intent android-location android-maps android-googleapiclient


    【解决方案1】:

    launch maps

    有很多资源可以帮助您学习这是一个示例。在真正的应用程序中,您可能希望使用自己的地图活动来处理意图;也许添加边界和相机以放大或其他...

    Location sf = new Location("");
    
    
      sf.setLatitude(37.7749);
      sf.setLongitude(-122.4194);
    
      requestLocation("your address");
    
    
    
    public  void requestLocation(Location location) {
    
    
    
        // Create a Uri from an intent string. Use the result to 
        //   create an Intent.
        Uri gmmIntentUri = Uri.parse("geo:" + location.getLatitude() + "," + location.getLongitude());
    
        // Create an Intent from gmmIntentUri. Set the action to 
        //   ACTION_VIEW
        Intent mapIntent = new Intent(Intent.ACTION_VIEW, 
        gmmIntentUri);
    
        // Make the Intent explicit by setting the Google Maps 
        //   package
        mapIntent.setPackage("com.google.android.apps.maps");
    
    
        if (mapIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(mapIntent, REQUEST_LOCATION);
        }
    }
    
    public  void requestLocation(String address) {
    
           // Create a Uri from an intent string. Use the result to create 
          //an Intent.
        Uri gmmIntentUri = Uri.parse("geo:" + address);
    
        // Make the Intent explicit by setting the Google Maps 
        //   package
        mapIntent.setPackage("com.google.android.apps.maps");
    
    
        if (mapIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(mapIntent, REQUEST_LOCATION);
        }
    
    }      
    

    【讨论】:

    • 添加了一个链接。请注意,代码不会缩放到该位置。我认为它在那里放了一个小灰点;没有标记...
    【解决方案2】:

    您可以在此处找到有关如何使用意图通过地址启动 Google 地图的概述:

    https://developers.google.com/maps/documentation/urls/android-intents

    【讨论】:

    • 我没有找到任何确切地址。有和我一样的地址吗?
    • 地址设置少了一行代码,抱歉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多