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);  
            }  
        }  
    }  
    

    }

  • 相关阅读:
    IBM Thread and Monitor Dump Analyzer for Java解决生产环境中的性能问题
    ORACLE中的字符串替换 replce、regexp_replace 和 translate
    ORA-01654 索引 无法通过 表空间扩展
    HTML篇之CSS样式:<button></button>按钮变成超链接<a></a>的样式
    HTML里用如何包含引用另一个html文件 .
    java程序中实现打开 某个指定浏览器
    Oracle查询数据库中所有表的记录数
    getOutputStream() has already been called for this response解释以及解决方法
    oracle索引,索引的建立、修改、删除
    各种组件的js 获取值 / js动态赋值
  • 原文地址:https://www.cnblogs.com/myy69/p/7019635.html
Copyright © 2011-2022 走看看