【问题标题】:How to open Google Maps without other apps that use the "geo" scheme being opened?如何在不打开其他使用“地理”方案的应用程序的情况下打开谷歌地图?
【发布时间】:2012-09-07 12:05:40
【问题描述】:

我有一个小型测试项目,其主要活动包含:

String myUri =  "geo:50.08818f,14.42021f?z=11";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(myUri));
startActivity(intent);

在我的安卓设备上,我有谷歌地图和一个使用地理方案的应用程序。 运行测试项目,出现一个带有 2 个选项的弹出窗口:如果我想打开我的应用程序,它会打开并在地图上设置给定位置,但如果我选择 Google 地图,地图会打开,一秒钟后,我的另一个应用启动并在其地图上设置位置。

我的问题是,如果我没有选择它,我不明白为什么我的其他应用程序会打开。 我的应用清单中的一段代码是:

<intent-filter >
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="geo" />
</intent-filter>

任何帮助将不胜感激,

谢谢

【问题讨论】:

  • 我有点困惑;您想创建一个意图并确保 Google 地图是唯一响应的应用吗?

标签: android android-intent geo


【解决方案1】:

你可以使用:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);

但它也可以启动 Navigator...


你也可以使用:

"google.navigation:q=an+address+city"

用于谷歌导航


这里是可用的Intent 列表:
http://developer.android.com/guide/appendix/g-app-intents.html

【讨论】:

    【解决方案2】:

    纬度和经度必须是小数。

    String myUri =  "geo:50.08818,14.42021?z=11";
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(myUri));
    startActivity(intent);
    

    【讨论】:

      【解决方案3】:

      您可以使用此 Intent 专门使用 Google 地图打开导航:

       Intent navigation = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=" +
                           String.valueOf(AppObj.getInstance().currentUserLocation.getLatitude())+","+
                           String.valueOf(AppObj.getInstance().currentUserLocation.getLongitude())+"&daddr="+
                           String.valueOf(task.getLatitude()) +","+ String.valueOf(task.getLongtitude())));
                           navigation.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
       startActivity(navigation);
      

      【讨论】:

        【解决方案4】:

        得到它的工作:

        String uri = "geo:" + gpsLat + "," + gpsLong + "?q=" + Uri.encode(gpsLat+ "," + gpsLong);
        startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
        

        希望有帮助

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-08-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-05-09
          • 2014-11-15
          相关资源
          最近更新 更多