如何在点击地址时打开谷歌地图应用程序?

问题描述 投票:0回答:2

我的应用程序中有一个地址参数说“921 Beverly Hills,California,CA-09001”点击这个我想要谷歌地图打开并显示这个确切地址的注释。我怎么做?任何线索?

android android-intent android-location android-maps android-googleapiclient
2个回答
2
投票

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);
    }

}      

0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.