简体   繁体   English

如何从 Android 中的普通 Activity 启动 MapActivity

[英]How to start a MapActivity from normal Activity in Android

I created a launcher MapActivity from new project and it is working fine.我从新项目创建了一个启动器MapActivity ,它工作正常。 Now I want start a MapActivity from normal activity like MainActivity.java to MapsActvity.java such that from MainActivity , it should send latitude and longitudes values for marker to show in MapActivity when a button in the main layout is clicked.现在我想从像MainActivity.javaMapsActvity.java这样的普通活动启动一个MapActivity ,这样从MainActivity ,当单击主布局中的按钮时,它应该发送标记的纬度和经度值以显示在MapActivity中。 I am thinking of using intent but I don't know how do it.我正在考虑使用意图,但我不知道该怎么做。

Intent i = new Intent();
startActivity(i);
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);

Thanks for your answer USKMobility, but i had to modify your code to use it :感谢您的回答 USKMobility,但我必须修改您的代码才能使用它:

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

Thanks!谢谢!

You can directly use this你可以直接使用这个

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

Pass the address , the above code uses inbuilt Maps and shows the address specified.传递address ,上面的代码使用内置地图并显示指定的address

Place this in your Manifest file把它放在你的Manifest文件中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM