我在活動中有一張圖片(地圖的圖片),我想在手機上打開具有特定地理坐標的谷歌地圖。我的以下代碼運行良好,并且我的應用程式正在午餐,但是當我單擊影像時,我的應用程式正在重新啟動。我檢查了其他問題,我的代碼似乎很好,所以我不知道可能出了什么問題。
MilleActivity.java
public class MilleActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mille);
ImageView map = (ImageView) findViewById(R.id.mapQC);
map.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openMap();
}
});
}
private void openMap() {
String uri = String.format("geo:46.81402244651992, -71.220484138461");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.maps");
startActivity(intent);
}
}
//}
activity_mille.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MilleActivity"
android:background="@color/white"
android:paddingTop="50dp">
<ImageView
android:layout_width="350dp"
android:layout_height="350dp"
android:gravity="center"
android:scaleType="centerInside"
android:src="@drawable/mille"
android:layout_centerHorizontal="true"
tools:layout_editor_absoluteY="20dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="350dp"
android:text="Film: 1987"
android:textColor="#000"
android:textSize="25sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Réalisateur: Ricardo Trogi"
android:textColor="#000"
android:textSize="25sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:text="Lieu: Québec"
android:textColor="#000"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Anecdote: Ricardo Trogi (réalisateur)"
android:textColor="#000"
android:textSize="18sp" />
<ImageView
android:id="@ id/mapQC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:baselineAlignBottom="true"
android:scaleType="centerInside"
android:src="@drawable/map" />
</LinearLayout>
</RelativeLayout>
uj5u.com熱心網友回復:
試試這個代碼
String latitude = "46";
String longitude = "71";
String uri = "https://www.google.com.tw/maps/place/" latitude "," longitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
你可以更換你想要latitude的longitude
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/443948.html
上一篇:一張一張保存GAN生成的圖片
