百度地图android使用教程,andriod开发教程 在android使用百度地图

andriod开发的过程中可能会涉及到再andriod使用百度地图的问题,这个问题的解决分为了三个步骤

第一步:打开百度开放平台,然后下载百度地图的sdk,之后再导入到这个项目中,就可以申请到自己的appkey。

第二步:创建一个layout,这个方面你可以自由发挥

1.

2.android:id="@+id/bmapView"

3.android:layout_width="fill_parent"

4.android:layout_height="0.0px"

5.android:layout_weight="2.07"

6.android:clickable="true"/>

android:id="@+id/bmapView"

android:layout_width="fill_parent"

android:layout_height="0.0px"

android:layout_weight="2.07"

android:clickable="true" />

第三部:建立一个activity。

private static LocationData locationData = new LocationData();

static MapView mMapView;

public LocationClient mLocationClient = null;

public BDLocationListener myListener = new MyLocationListener();

private MapController mMapController;

private MKSearch mkSearch;

private GeoPoint point2;

private MKMapViewListener mMapListener = null;

private LocationClientOption option;

必须在oncreate中初始化百度地图的key,而且是在setContentView的前面初始化。

MapController是对地图的控制,比如缩放,zoom级别,地图的中心点等等

mMapController.setCenter(point);//设置地图中心点mMapController.setZoom(15);//设置地图zoom级别mMapController.enableClick(true);

mMapView.setOnTouchListener(null);

定位的核心代码:BDLocationListener

private class MyLocationListener implements BDLocationListener {

//大概一秒钟定位一次@Override

public void onReceiveLocation(BDLocation location) {

if (location == null)

return;

if (flag_new == true) {

myPoint = new GeoPoint((int) (location.getLatitude() * 1e6),

(int) (location.getLongitude() * 1e6));

locationData.latitude = location.getLatitude();

locationData.longitude = location.getLongitude();

locationData.direction = 2.0f;

locationData.accuracy = location.getRadius();//获取服务locationData.direction = location.getDerect();

// strAdd = location.getAddrStr().toString();

mMapView.refresh();//此处刷新必须有//定位本地位置,此句没有,则无法定位mMapController.animateTo(new GeoPoint(

(int) (locationData.latitude * 1e6),

(int) (locationData.longitude * 1e6)));

MyLocationOverlay myLocationOverlay = new MyLocationOverlay(

mMapView);

//手动将位置源置为天安门,在实际应用中,请使用百度定位SDK获取位置信息,要在SDK中显示一个位置,需要//使用百度经纬度坐标(bd09ll)locationData.direction = 2.0f;

myLocationOverlay.setData(locationData);

mMapView.getOverlays().add(myLocationOverlay);

mMapView.refresh();

mMapView.getController().animateTo(

new GeoPoint((int) (lat), (int) (lon)));

flag_new = false;

}

}

要进行路线的查询的就要实现MKSearch()中的MKSearchListener()

其实百度地图给出了很详细的api资料了,可以对着来一步一步实现

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值