zoukankan      html  css  js  c++  java
  • 单车家族(结对项目)3

    地图定位

    1、初始化

    SDKInitializer.initialize(getApplicationContext());//我测试在Application的onCreate()不行,必须在activity的onCreate()中

    2、配置map参数

    [html] view plain copy
    private void initMap() {
    // 地图初始化
    mMapView = (MapView) findViewById(R.id.id_bmapView);
    mBaiduMap = mMapView.getMap();
    // 开启定位图层
    mBaiduMap.setMyLocationEnabled(true);
    // 定位初始化
    mlocationClient = new LocationClient(this);
    mlocationClient.registerLocationListener(myListener);
    LocationClientOption option = new LocationClientOption();
    option.setOpenGps(true); // 打开gps
    option.setCoorType("bd09ll"); // 设置坐标类型
    option.setScanSpan(5000);//设置onReceiveLocation()获取位置的频率
    option.setIsNeedAddress(true);//如想获得具体位置就需要设置为true
    mlocationClient.setLocOption(option);
    mlocationClient.start();
    mCurrentMode = MyLocationConfiguration.LocationMode.FOLLOWING;
    mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(
    mCurrentMode, true, null));
    myOrientationListener = new MyOrientationListener(this);
    //通过接口回调来实现实时方向的改变
    myOrientationListener.setOnOrientationListener(new MyOrientationListener.OnOrientationListener() {
    @Override
    public void onOrientationChanged(float x) {
    mCurrentX = x;
    }
    });
    myOrientationListener.start();
    mSearch = RoutePlanSearch.newInstance();
    mSearch.setOnGetRoutePlanResultListener(this);
    initMarkerClickEvent();
    }

    3、获取当前地址

    [html] view plain copy
    public class MyLocationListenner implements BDLocationListener {

    @Override  
    public void onReceiveLocation(BDLocation bdLocation) {  
        // map view 销毁后不在处理新接收的位置  
        if (bdLocation == null || mMapView == null) {  
            return;  
        }  
        MyLocationData locData = new MyLocationData.Builder()  
                .accuracy(bdLocation.getRadius())  
                .direction(mCurrentX)//设定图标方向     // 此处设置开发者获取到的方向信息,顺时针0-360  
                .latitude(bdLocation.getLatitude())  
                .longitude(bdLocation.getLongitude()).build();  
        mBaiduMap.setMyLocationData(locData);  
        currentLatitude = bdLocation.getLatitude();  
        currentLongitude = bdLocation.getLongitude();  
        current_addr.setText(bdLocation.getAddrStr());  
        currentLL = new LatLng(bdLocation.getLatitude(),  
                bdLocation.getLongitude());  
        startNodeStr = PlanNode.withLocation(currentLL);  
        //option.setScanSpan(5000),每隔5000ms这个方法就会调用一次,而有些我们只想调用一次,所以要判断一下isFirstLoc  
        if (isFirstLoc) {  
            isFirstLoc = false;  
            LatLng ll = new LatLng(bdLocation.getLatitude(),  
                    bdLocation.getLongitude());  
            MapStatus.Builder builder = new MapStatus.Builder();  
            //地图缩放比设置为18  
            builder.target(ll).zoom(18.0f);  
            mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));  
            changeLatitude = bdLocation.getLatitude();  
            changeLongitude = bdLocation.getLongitude();  
            if (!isServiceLive) {  
                addOverLayout(currentLatitude, currentLongitude);  
            }  
        }  
    }  
    

    }

  • 相关阅读:
    springboot将接口内容快速生成接口文档导出,swagger将api文档以表格文档导出
    IDEA2019.2或2019.3激活码失效后重新激活教程
    Java代码自动生成,生成前端vue+后端controller、service、dao代码,根据表名自动生成增删改查功能
    百度网盘下载慢解决办法,最新.浏览器下载速度突破方法
    smartGit 版本19.1没有settings文件如何破解
    arp欺骗软件(来自互联网)
    关闭学生端v1.0(附链接)
    [TODO]multiaet/set/multimap/map
    树状数组【洛谷3374】
    luoguP1439
  • 原文地址:https://www.cnblogs.com/myy69/p/7019635.html
Copyright © 2011-2022 走看看