如何显示从我的位置到保存的经纬度的方向

问题描述 投票:0回答:1

我尝试了几个例子,但它没有显示方向并且不断出错。我希望它就像当我点击方向按钮时,它会重定向到谷歌地图并显示从我当前位置到给定目的地纬度和经度的方向。

它是来自android studio的java编码

if (destData != null) {
        final String dataHold = (String) destData.get("coordinate");
        dest.setText(dataHold);
        destAddress = dest.toString();

        direction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (source!=null){
                    String packageName = "com.google.android.apps.maps";
                    String query = String.format("http://maps.google.com/maps?daddr=%s",destAddress);

                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(query));
                    intent.setPackage(packageName);
                    startActivity(intent);

                }else {
                    Toast.makeText(DirectionActivity.this,"please get current location",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

我得到的当前输出的图片

android google-maps direction
1个回答
0
投票

使用此方法并提供坐标值。

 public static void startNavigationOnGm(Context context,double lat, double lng){
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
            Uri.parse("http://maps.google.com/maps?daddr="+lat+","+lng));
    context.startActivity(intent);
}
© www.soinside.com 2019 - 2024. All rights reserved.