如何在单击按钮时打开内置打开 google 地图
How to open inbuilt open google map on button click
请建议我,我是 android 的新手 android 如何打开内置 Google 按钮点击地图 android 我只有一个图像按钮。
如何在单击按钮时打开内置打开 google 地图
在 onclick 监听器中输入此代码
String uri = "http://maps.google.com/maps?saddr=" + sourceLatitude + "," + sourceLongitude + "&daddr=" + destinationLatitude + "," + destinationLongitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
希望对您有所帮助。
例子:-
btn_click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Uri gmmIntentUri = Uri.parse("geo:0,0?q=");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
}
}, 1000);
}
});
String uri = "http://maps.google.com/maps?saddr=" + sourceLatitude + "," + sourceLongitude + "&daddr=" + destinationLatitude + "," + destinationLongitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
开始活动(意图);
请建议我,我是 android 的新手 android 如何打开内置 Google 按钮点击地图 android 我只有一个图像按钮。 如何在单击按钮时打开内置打开 google 地图
在 onclick 监听器中输入此代码
String uri = "http://maps.google.com/maps?saddr=" + sourceLatitude + "," + sourceLongitude + "&daddr=" + destinationLatitude + "," + destinationLongitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
希望对您有所帮助。
例子:-
btn_click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Uri gmmIntentUri = Uri.parse("geo:0,0?q=");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
}
}, 1000);
}
});
String uri = "http://maps.google.com/maps?saddr=" + sourceLatitude + "," + sourceLongitude + "&daddr=" + destinationLatitude + "," + destinationLongitude;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
开始活动(意图);