百度地图定位
目标:根据百度地图开发者文档,编写百度地图定位程序。在地图上标出所在的位置。
首先从官网下载SDK然后导入

然后是JAVA文件中代码,定位监听函数等
public class MyLocationListener extends BDAbstractLocationListener {
@Override
public void onReceiveLocation(BDLocation location) {
//mapView 销毁后不在处理新接收的位置
if (location == null || mMapView == null){
return;
}
MyLocationData locData = new MyLocationData.Builder()
.accuracy(location.getRadius())
// 此处设置开发者获取到的方向信息,顺时针0-360
.latitude(location.getLatitude())
.longitude(location.getLongitude())
.direction(location.getDirection())
.build();
mBaiduMap.setMyLocationData(locData);
MyLocationConfiguration configuration = new MyLocationConfiguration(
MyLocationConfiguration.LocationMode.NORMAL, false, mMarker);
mBaiduMap.setMyLocationConfiguration(configuration);
跑起来的样子:

最后是源码
本文详细介绍如何使用百度地图SDK实现定位功能。从下载SDK开始,逐步介绍如何在Java环境中配置并使用定位监听函数,最终实现在地图上显示当前位置。代码实例丰富,便于读者快速上手。
1万+

被折叠的 条评论
为什么被折叠?



