Android - set map, positioning, navigation in one

effect video

digital map

map

digital map

Modify location icon

MyLocationConfiguration.LocationMode mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
 BitmapDescriptor mCurrentMarker = BitmapDescriptorFactory.fromResource(R.drawable.icon_location);
map.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true, mCurrentMarker,0x00000000,0x00000000));

position

The new version of the API obtains location information by inheriting BDAbstractLocationListener

class MyBaiduMap extends BDAbstractLocationListener {
        @Override
        public void onReceiveLocation(BDLocation bdLocation) {
            Latitude = bdLocation.getLatitude();//获取纬度
            Longitude = bdLocation.getLongitude();//获取经度
            if (bdLocation.getLocType() == com.baidu.location.BDLocation.TypeGpsLocation || bdLocation.getLocType() == com.baidu.location.BDLocation.TypeNetWorkLocation) {
                navigateTo(bdLocation);
            }
            int error  = bdLocation.getLocType();//162
            mCityName = bdLocation.getCity();
            if (mCityName!= null && cityFalg == false){
                UpdateView();
                cityFalg = true;
            }
            //Toast.makeText(MainActivity.this,mCityName,Toast.LENGTH_LONG).show();
            //网络定位失败,因为百度定位服务无法解密请求查询,请检查so文件!"
            //Toast.makeText(MainActivity.this,"error"+error,Toast.LENGTH_LONG).show();
        }
    }
//if (isFirstLocate){
            LatLng lng = new LatLng(location.getLatitude(),location.getLongitude());//指定经纬度
            MapStatusUpdate update = MapStatusUpdateFactory.newLatLng(lng);
            map.animateMapStatus(update);
            update = MapStatusUpdateFactory.zoomTo(16f);//百度地图缩放级别限定在3-19
            map.animateMapStatus(update);
            isFirstLocate = false;
        //}
        MyLocationData.Builder builder = new MyLocationData.Builder();
        builder.latitude(location.getLatitude());//纬度
        builder.longitude(location.getLongitude());//经度
        MyLocationData locationData = builder.build();
        map.setMyLocationData(locationData);

navigation

navigation

end words

This article is only used to record my learning process

Guess you like

Origin blog.csdn.net/News53231323/article/details/123788997