如何在Google地图中设置多个方向点?

时间:2018-03-09 13:00:59

标签: android google-maps android-studio android-intent

enter image description here

以下是按钮链接到谷歌地图的代码,基于文本视图地址。

button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view){
                    String address = textViewAddress.getText().toString();
                    String addressb = textViewAddressB.getText().toString();
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q="+address));
                    view.getContext().startActivity(intent);
                }
            });

如何在Google地图中使用多个目的地/点?因此,如果我创建了另一个文本视图地址b,我想显示位置地址a到地址b到地址c,如上图所示。也可能是Waze的意图吗?

1 个答案:

答案 0 :(得分:1)

您可以使用waypoints来引用此API Documentation ..您可以添加多个目的地

Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/dir/?api=1&origin=18.519513,73.868315&destination=18.518496,73.879259&waypoints=18.520561,73.872435|18.519254,73.876614|18.52152,73.877327|18.52019,73.879935&travelmode=driving");
Intent intent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
intent.setPackage("com.google.android.apps.maps");
try {
    startActivity(intent);
} catch (ActivityNotFoundException ex) {
    try {
        Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
        startActivity(unrestrictedIntent);
    } catch (ActivityNotFoundException innerEx) {
        Toast.makeText(this, "Please install a maps application", Toast.LENGTH_LONG).show();
    }
}

<强>更新 您也可以查看question