android 百度地图驾车导航,使用百度地图API实现驾车导航

73596687_2.png

73596687_3.png

73596687_4.png

进入应用后首先显示蓝色点为当前位置,可以输入目的地来形成导航线路(图1),也可以点选地图上任意点来形成导航线路(图2,3),选定点后,在地图上会标注红色定位点,点击开始导航按钮后便会形成最佳驾车线路。

接下来看看实现步骤:

首先是工程结构

其中libs下面是申请百度开发者后到地图API下下载Android的地图支持包并导入工程,这里不再细说。

然后是布局文件:

[html]

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="目的地:"

android:textSize="17sp" />

android:id="@+id/et_destination"

android:layout_width="fill_parent"

android:hint="输入目的地名称或在地图上点选"

android:textSize="14sp"

android:layout_height="wrap_content" />

android:layout_width="fill_parent"

android:layout_height="wrap_content" >

android:id="@+id/btn_navi"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="开始导航" />

android:id="@+id/btn_clear"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="清除路线" />

android:id="@+id/bmapsView"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:clickable="true" />

然后是实现自定义的地图图层MyItemizedOverlay.java,这个类的作用是实现可点击地图图层的作用,点击地图后,便可以显示当前位置的经纬度,并可设置为目的地。

[java]

/**

* 自定义图层

* @author Ryan

*/

public class MyItemizedOverlay extends ItemizedOverlay {

private ArrayList mOverlays = new ArrayList();

private Context context;

public MyItemizedOverlay(Context context,Drawable drawale) {

super(boundCenterBottom(drawale));

this.context=context;

}

@Override

protected OverlayItem createItem(int i) {

return mOverlays.get(i);

}

@Override

public int size() {

return mOverlays.size();

}

// 点击地图标注显示的内容

@Override

protected boolean onTap(int index) {

//这个方法的重写弹出信息等

return true;

}

@Override

public void draw(Canvas canvas, MapView mapView, boolean shadow) {

super.draw(canvas, mapView, shadow);<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值