android百度地图开发V4.5最新版(3)---计算地图上俩点之间的距离

接着前面的继续,先来看一个图片:

一个是获取自己的地理位置信息,一个是获取固定点到自己的距离。

俩个需求,第一个需求我们已经完成。有需要的可以看我的文章ndroid百度地图开发V4.5最新版(2)---地理位置的获取

接着实现第二个需求即距离的计算。

废话不多说,直接撸代码。

1,建立xml文件。代码如下:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="请输入俩个点的经纬度:"
    android:layout_marginLeft="10dip"
    android:textColor="@color/colorAccent"
    android:textSize="22dip"
    />
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="第一个点的经纬度:"
    android:layout_marginLeft="10dip"
    android:textColor="@color/colorAccent"
    android:textSize="22dip"
    />
<EditText
    android:id="@+id/et_erjing"
    android:layout_width="match_parent"
    android:layout_height="50dip"
    android:layout_marginTop="22dip"
    android:text="39.951721"
    />
<EditText
    android:id="@+id/et_erwei"
    android:layout_width="match_parent"
    android:layout_height="50dip"
    android:layout_marginTop="22dip"
    android:text="116.288394"
    />
<TextView

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="第二个点的经纬度:"
    android:layout_marginLeft="10dip"
    android:textColor="@color/colorAccent"
    android:textSize="22dip"
    />
<EditText
    android:id="@+id/et_yijing"
    android:layout_width="match_parent"
    android:layout_height="50dip"
    android:layout_marginTop="22dip"
    android:text="39.951721"
    />
<EditText
    android:id="@+id/et_yiwei"
    android:layout_width="match_parent"
    android:layout_height="50dip"
    android:layout_marginTop="22dip"
    android:text="116.288414"
    />
<Button
    android:id="@+id/bt_jisuan"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="计算经纬度距离"
    android:layout_gravity="center"
    />
<TextView
    android:id="@+id/tv_jieguo"
    android:layout_width="match_parent"
    android:layout_height="50dip" />
2.获取俩个点:

LatLng gp1=new LatLng(Double.parseDouble(et_yijing.getText().toString()),Double.parseDouble(et_yiwei.getText().toString()));
LatLng gp2=new LatLng(Double.parseDouble(et_erjing.getText().toString()),Double.parseDouble(et_erwei.getText().toString()));
3:计算距离:

Double distance= DistanceUtil. getDistance(gp1, gp2);
tv_jieguo.setText(
distance
+"");
效果图如下所示:

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值