【问题标题】:How to start a MapActivity from normal Activity in Android如何从 Android 中的普通 Activity 启动 MapActivity
【发布时间】:2015-12-23 02:18:24
【问题描述】:

我从新项目创建了一个启动器MapActivity,它工作正常。现在我想从MainActivity.javaMapsActvity.java 这样的正常活动开始一个MapActivity,这样从MainActivity 开始,当单击主布局中的按钮时,它应该发送标记的纬度和经度值以在MapActivity 中显示.我正在考虑使用意图,但我不知道该怎么做。

Intent i = new Intent();
startActivity(i);

【问题讨论】:

    标签: java android google-maps-api-3 maps google-maps-markers


    【解决方案1】:
    In MainActivity on button click 
    
    Intent intent = new Intent(this, MapsActvity.class);
    intent.putExtra("latitute", 34.8098080980);
    intent.putExtra("longitude", 67.09098898);
    startActivity(intent);
    
    In MapActivity.java onCreate method get lattitude and longitude and use it
            Intent intent1 = getIntent();
            double lat = intent1.getDoubleExtra("latitute", 0);
            double lng  = intent1.getDoubleExtra("longitude",0);
    

    【讨论】:

      【解决方案2】:

      感谢您对 USKMobility 的回答,但我必须修改您的代码才能使用它:

       Intent intent = new Intent(MainActivity.this, MapsActivity.class);
       intent.putExtra("latitute", 34.8098080980);
       intent.putExtra("longitude", 67.09098898);
       startActivity(intent);
      

      谢谢!

      【讨论】:

        【解决方案3】:

        你可以直接用这个

         Intent geoIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri
                                        .parse("geo:0,0?q=" + address));
         startActivity(intent);
        

        传递address,上面的代码使用内置的地图并显示指定的address

        将其放入您的 Manifest 文件中

        <uses-library android:name="com.google.android.maps" />
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-04-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多