百度地图
来源:互联网 发布:淘宝买同款违法吗 编辑:程序博客网 时间:2024/06/01 08:24
主界面=====================================================
public class MainActivity extends ActionBarActivity {
private MapView mMapView;
private BaiduMap mBaiduMap;
public LocationClient mLocationClient = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_main);
mMapView = (MapView) findViewById(R.id.bmapView);
mBaiduMap = mMapView.getMap();
mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
BDLocationListener myListener = new MyLocationListener(mBaiduMap);
//普通地图
//
mLocationClient = new LocationClient(getApplicationContext());
initLocation();
//声明LocationClient类
mLocationClient.registerLocationListener( myListener ); //注册监听函数
mLocationClient.start();
}
private void initLocation() {
LocationClientOption option = new LocationClientOption();
option.setLocationMode(LocationMode.Hight_Accuracy
);//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
option.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系
int span=1000;
option.setScanSpan(0);//可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
option.setIsNeedAddress(true);//可选,设置是否需要地址信息,默认不需要
option.setOpenGps(true);//可选,默认false,设置是否使用gps
option.setLocationNotify(true);//可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
option.setIsNeedLocationDescribe(true);//可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
option.setIsNeedLocationPoiList(true);//可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
option.setIgnoreKillProcess(false);//可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
option.SetIgnoreCacheException(false);//可选,默认false,设置是否收集CRASH信息,默认收集
option.setEnableSimulateGps(false);//可选,默认false,设置是否需要过滤gps仿真结果,默认需要
mLocationClient.setLocOption(option);
}
}
布局============================================================
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bawie.test.MainActivity" >
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
</RelativeLayout>
帮助类======================================================================
public class MyLocationListener implements BDLocationListener {
private LocationMode mCurrentMode=LocationMode.COMPASS;
private BitmapDescriptor mCurrentMarker;
BaiduMap mBaiduMap;
public MyLocationListener(BaiduMap mBaiduMap) {
this.mBaiduMap=mBaiduMap;
}
@Override
public void onReceiveLocation(BDLocation location) {
// TODO Auto-generated method stub
//Receive Location
StringBuffer sb = new StringBuffer(256);
sb.append("time : ");
sb.append(location.getTime());
sb.append("\nerror code : ");
sb.append(location.getLocType());
sb.append("\nlatitude : ");
sb.append(location.getLatitude());
sb.append("\nlontitude : ");
sb.append(location.getLongitude());
sb.append("\nradius : ");
sb.append(location.getRadius());
if (location.getLocType() == BDLocation.TypeGpsLocation){// GPS定位结果
sb.append("\nspeed : ");
sb.append(location.getSpeed());// 单位:公里每小时
sb.append("\nsatellite : ");
sb.append(location.getSatelliteNumber());
sb.append("\nheight : ");
sb.append(location.getAltitude());// 单位:米
sb.append("\ndirection : ");
sb.append(location.getDirection());// 单位度
sb.append("\naddr : ");
sb.append(location.getAddrStr());
sb.append("\ndescribe : ");
sb.append("gps定位成功");
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation){// 网络定位结果
sb.append("\naddr : ");
sb.append(location.getAddrStr());
//运营商信息
sb.append("\noperationers : ");
sb.append(location.getOperators());
sb.append("\ndescribe : ");
sb.append("网络定位成功");
}
sb.append("\nlocationdescribe : ");
sb.append(location.getLocationDescribe());// 位置语义化信息
List<Poi> list = location.getPoiList();// POI数据
if (list != null) {
sb.append("\npoilist size = : ");
sb.append(list.size());
for (Poi p : list) {
sb.append("\npoi= : ");
sb.append(p.getId() + " " + p.getName() + " " + p.getRank());
}
}
Log.i("BaiduLocationApiDem", sb.toString());
// 开启定位图层
mBaiduMap.setMyLocationEnabled(true);
// 构造定位数据
MyLocationData locData = new MyLocationData.Builder()
.accuracy(location.getRadius())
// 此处设置开发者获取到的方向信息,顺时针0-360
.direction(100).latitude(40.0491290000)
.longitude(116.3064050000).build();
// 设置定位数据
mBaiduMap.setMyLocationData(locData);
// 设置定位图层的配置(定位模式,是否允许方向信息,用户自定义定位图标)
mCurrentMarker = BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher);
MyLocationConfiguration config = new MyLocationConfiguration(mCurrentMode, true, mCurrentMarker);
mBaiduMap.setMyLocationConfigeration(config);
// 当不需要定位图层时关闭定位图层
// mBaiduMap.setMyLocationEnabled(false);
}
}
导包======================================
arm64-v8a
armeabi
BaiduLBS-Android
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- 百度地图
- window7 安装 window service 2012 update
- mongoBD的基本操作命令列表
- 第一条博客
- 医院大数据解决方案
- 准备加入软件开发行业的朋友可以看看
- 百度地图
- 小话设计模式(六)适配器模式
- AR或许会带来新的网络隐患 最明智的是未雨绸缪
- Android数据篇—SharedPreferences
- XListView下拉刷新上拉加载
- 第26周-window程序设计(基础篇)-第5章(图形基础)-取得设备内容的多方法
- 二叉树的镜像
- Fragment+ViewPager+Button
- XML解析之pull