百度地图自动定位
来源:互联网 发布:山东大学网络教育网 编辑:程序博客网 时间:2024/05/01 02:00
1.初始化地图
private static MapView mMapView = null;
private BaiduMap mBaiduMap = null;
private LocationClient locationClient = null;// 定位相关声明
private double mCurrentLantitude ,mCurrentLongitude ;// 定位经纬度
private boolean isFirstLoc = true;// 是否首次定位
mMapView = (MapView) findViewById(R.id.vbmapView);
mMapView.showZoomControls(false);
mBaiduMap = mMapView.getMap();
MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(12.0f);
mBaiduMap.setMapStatus(msu);
2.设置定位参数
private void setLocation() {
// 开启定位图层
mBaiduMap.setMyLocationEnabled(true);
locationClient = new LocationClient(
VenueOptionsActivity.this.getApplicationContext()); // 实例化LocationClient类
locationClient.registerLocationListener(myListener); // 注册监听函数
/** 设置参数 */
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true); // 打开GPS
option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);// 设置定位模式
option.setCoorType("bd09ll"); // 返回的定位结果是百度经纬度,默认值gcj02
option.setScanSpan(5000); // 设置发起定位请求的间隔时间为5000ms
option.setIsNeedAddress(true); // 返回的定位结果包含地址信息
option.setNeedDeviceDirect(true); // 返回的定位结果包含手机机头的方向
locationClient.setLocOption(option);
locationClient.start(); // 开始定位
locationClient.requestLocation();
// baiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); // 设置为一般地图
// baiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE); //设置为卫星地图
// baiduMap.setTrafficEnabled(true); //开启交通图
}
3.定位监听
/** 定位监听 */
BDLocationListener myListener = new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation location) {
// map view 销毁后不在处理新接收的位置
if (location == null || mMapView == null)
return;
MyLocationData locData = new MyLocationData.Builder()
.accuracy(location.getRadius())
// 此处设置开发者获取到的方向信息,顺时针0-300
.direction(100).latitude(location.getLatitude())
.longitude(location.getLongitude()).build();
mBaiduMap.setMyLocationData(locData); // 设置定位数据
mCurrentLantitude = location.getLatitude();
mCurrentLongitude = location.getLongitude();
if (isFirstLoc) {
isFirstLoc = false;
LatLng ll = new LatLng(location.getLatitude(),
location.getLongitude());
MapStatusUpdate u = MapStatusUpdateFactory
.newLatLngZoom(ll, 14); // 设置地图中心点以及缩放级别
mBaiduMap.animateMapStatus(u);
MapUtil.setCurrentLocation(ll);
Log.e("mLantitude, mLongitude", "mLantitude, mLongitude"+mCurrentLantitude+" "+mCurrentLongitude);
showLocation(mCurrentLantitude, mCurrentLongitude);// 显示获取地址信息
}
}
};
- 百度地图自动定位
- android百度地图自动定位
- Android 百度地图定位(手动+自动)
- Android 百度地图定位(手动+自动)
- 百度地图自定义标注物+自动定位
- 借助百度地图api实现显示地图,自动定位功能
- 百度地图 定位 地图
- 百度地图,百度定位。
- 手机自动定位 百度地图API使用的文章
- 手机自动定位 百度地图API使用的文章
- 百度地图API自动定位和3种导航
- 百度地图API实现自动定位城市,省市二联重新地图重新定位
- 百度地图之定位
- Android 百度地图 定位
- Android百度地图定位
- 百度地图定位基础
- 百度地图多点定位
- 百度地图定位问题
- [iOS]Reason: image not found 解决办法
- myeclipse 清理项目缓存的几大步骤
- 学Android---Intent
- ajax后台返回值乱码
- python2和python3的区别 (转载)
- 百度地图自动定位
- 【SSH项目实战】国税协同平台-2.环境搭建和整合
- BroadcastRecevier(广播)
- 除法(division,UVa 725)
- 数据结构——整数的四则运算
- 什么是PPA
- 汉语字典项目总结
- [LeetCode]House Robber
- jetty 部署java web工程;报java.err.no jdk错误