【问题标题】:How to open **Google Maps** application from my current application?如何从我当前的应用程序中打开 **Google Maps** 应用程序?
【发布时间】:2018-04-23 14:47:04
【问题描述】:

如何在当前应用程序的按钮点击事件中打开 Google 地图 应用程序。

【问题讨论】:

标签: android google-maps


【解决方案1】:

使用下面的行

String uri = "http://maps.google.com/";
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
            intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            startActivity(intent);

这将在地图应用程序中重定向。

【讨论】:

    【解决方案2】:

    您可以打开谷歌地图,意图给出您的起点和终点。

    Intent navigation = new Intent(Intent.ACTION_VIEW, Uri
            .parse("http://maps.google.com/maps?saddr="
                    + Constants.latitude + ","
                    + Constants.longitude + "&daddr="
                    + latitude + "," + longitude));
    startActivity(navigation);
    

    这会打开任何地图应用程序。表示浏览器或谷歌地图应用程序。如果您只想要谷歌地图并摆脱对话框,您可以向意图提示您要使用哪个包。

    startActivity() 之前添加:

    intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
    

    【讨论】:

      【解决方案3】:

      你必须使用Intent

      这里有一个真实示例

      http://www.tutorialforandroid.com/2009/10/launching-other-application-using-code.html

      这里有一个理论示例

      Open another application from your own (intent)

      这里有 Android 文档

      http://developer.android.com/reference/android/content/Intent.html

      希望对您有所帮助! :)

      【讨论】:

        【解决方案4】:

        您可以通过在 AndroidManifes.xml 中指定“intent-filters”来做到这一点;有关如何从您的应用程序启动 google 应用程序的更多信息,请参阅此链接:Intents List: Invoking Google Applications on Android Devices

        【讨论】:

          【解决方案5】:
          WebView view=(WebView) findViewById(R.id.w);    
          Button button=(Button) findViewById(R.id.nxt);
          
          button.setOnClickListener(new OnClickListener() {
                          public void onClick(View v) {
                               view.loadUrl("http://maps.google.co.in/maps?hl=en&tab=wl");
                              }
                                  };
          

          【讨论】:

            【解决方案6】:

            你可以使用这样的东西: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);

            【讨论】:

              【解决方案7】:

              这是从我当前的应用调用 google maps 的另一种方式。

              String SettingsPage = "com.google.android.apps.maps/com.google.android.maps.MapsActivity";
              
                              try
                              {
                              Intent intent = new Intent(Intent.ACTION_MAIN);             
                              intent.setComponent(ComponentName.unflattenFromString(SettingsPage));             
                              intent.addCategory(Intent.CATEGORY_LAUNCHER );             
                              startActivity(intent); 
                              }
                              catch (ActivityNotFoundException e)
                              {
                               Log.e("Activity Not Found","");
                              }
                              catch (Exception e) {
                                   Log.e("Activity Not Found",""+e);
                              }
              

              【讨论】:

                【解决方案8】:

                使用这个。 希望它对你有用:

                 Button showMap = (Button) findViewById(R.id.btn_showMap);
                 showMap .setOnClickListener(new OnClickListener()
                 {
                 public void onClick(View v){
                 Intent i = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:"+ latitude +","+ longitude ));
                 startActivity(i);
                 }
                 });
                

                【讨论】:

                  猜你喜欢
                  • 2019-08-12
                  • 1970-01-01
                  • 2019-08-01
                  • 2011-09-06
                  • 2020-03-10
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2015-12-02
                  相关资源
                  最近更新 更多