Java Code Examples for com.baidu.mapapi.map.MapStatusUpdateFactory#newMapStatus()

The following examples show how to use com.baidu.mapapi.map.MapStatusUpdateFactory#newMapStatus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveLocation(BDLocation bdLocation) {
    //查看定位结果
    Log.d("Tag", "定位返回----" + bdLocation.getAddrStr());

    //定位成功后,把定位的点,设置地图的中心点
    //包装经纬,从定位信息中,获取经纬度
    LatLng currentLatLng = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude());

    //构建地图状态
    MapStatus status = new MapStatus.Builder()
            //包装经纬度
            .target(currentLatLng)
            //缩放等级
            .zoom(15)
            //构建
            .build();
    //通过地图工厂设置地图状态
    MapStatusUpdate update = MapStatusUpdateFactory.newMapStatus(status);
    //更新地图界面
    mBaiduMap.setMapStatus(update);

}
 
Example 2
Source File: MapActivity.java    From foodie-app with Apache License 2.0 5 votes vote down vote up
private void startLocationOverlap() {
    //开启定位图层
    mBaiduMap.setMyLocationEnabled(true);
    //构造定位数据
    MyLocationData locData = new MyLocationData.Builder()
            .accuracy(mLocation.getRadius())
            // 此处设置开发者获取到的方向信息,顺时针0-360
            .direction(100).latitude(mLocation.getLatitude())
            .longitude(mLocation.getLongitude()).build();
    // 设置定位数据
    mBaiduMap.setMyLocationData(locData);
    // 设置定位图层的配置(定位模式,是否允许方向信息,用户自定义定位图标)
    //构建Marker图标
    BitmapDescriptor bitmap = BitmapDescriptorFactory
            .fromResource(R.drawable.my_location);
    //bitmap.
    MyLocationConfiguration config = new MyLocationConfiguration(MyLocationConfiguration.LocationMode.NORMAL, true, bitmap);
    mBaiduMap.setMyLocationConfigeration(config);
    //中心点为我的位置
    LatLng cenpt = new LatLng(locData.latitude, locData.longitude);
    //定义地图状态
    MapStatus mMapStatus = new MapStatus.Builder()
            .target(cenpt)
            .zoom(mCurrentLevel)
            .build();
    //定义MapStatusUpdate对象,以便描述地图状态将要发生的变化
    MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus);
    //改变地图状态
    mBaiduMap.setMapStatus(mMapStatusUpdate);
    // 当不需要定位图层时关闭定位图层
    //mBaiduMap.setMyLocationEnabled(false);
}
 
Example 3
Source File: MainActivity.java    From MoveMapLocation with Apache License 2.0 4 votes vote down vote up
private void initView() {
    mMapView = (MapView) findViewById(R.id.main_bdmap);
    mBaiduMap = mMapView.getMap();

    poisLL = (ListView) findViewById(R.id.main_pois);

    topRL = (RelativeLayout) findViewById(R.id.main_top_RL);

    searchAddress = (EditText) findViewById(R.id.main_search_address);

    searchPois = (ListView) findViewById(R.id.main_search_pois);

    //定义地图状态
    MapStatus mMapStatus = new MapStatus.Builder().zoom(18).build();
    MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus);
    //改变地图状态
    mBaiduMap.setMapStatus(mMapStatusUpdate);

    //地图状态改变相关监听
    mBaiduMap.setOnMapStatusChangeListener(this);

    //开启定位图层
    mBaiduMap.setMyLocationEnabled(true);

    //定位图层显示方式
    mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;

    /**
     * 设置定位图层配置信息,只有先允许定位图层后设置定位图层配置信息才会生效
     * customMarker用户自定义定位图标
     * enableDirection是否允许显示方向信息
     * locationMode定位图层显示方式
     */
    mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, null));

    //初始化定位
    mLocClient = new LocationClient(this);
    //注册定位监听
    mLocClient.registerLocationListener(this);

    //定位选项
    LocationClientOption option = new LocationClientOption();
    /**
     * coorType - 取值有3个:
     * 返回国测局经纬度坐标系:gcj02
     * 返回百度墨卡托坐标系 :bd09
     * 返回百度经纬度坐标系 :bd09ll
     */
    option.setCoorType("bd09ll");
    //设置是否需要地址信息,默认为无地址
    option.setIsNeedAddress(true);
    //设置是否需要返回位置语义化信息,可以在BDLocation.getLocationDescribe()中得到数据,ex:"在天安门附近", 可以用作地址信息的补充
    option.setIsNeedLocationDescribe(true);
    //设置是否需要返回位置POI信息,可以在BDLocation.getPoiList()中得到数据
    option.setIsNeedLocationPoiList(true);
    /**
     * 设置定位模式
     * Battery_Saving
     * 低功耗模式
     * Device_Sensors
     * 仅设备(Gps)模式
     * Hight_Accuracy
     * 高精度模式
     */
    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
    //设置是否打开gps进行定位
    option.setOpenGps(true);
    //设置扫描间隔,单位是毫秒 当<1000(1s)时,定时定位无效
    option.setScanSpan(1000);

    //设置 LocationClientOption
    mLocClient.setLocOption(option);

    //开始定位
    mLocClient.start();

}