Search in sources :

Example 46 with LatLng

use of com.amap.api.maps.model.LatLng in project DoraemonKit by didi.

the class AMapUtil method convertArrList.

/**
 * 把集合体的LatLonPoint转化为集合体的LatLng
 */
public static ArrayList<LatLng> convertArrList(List<LatLonPoint> shapes) {
    ArrayList<LatLng> lineShapes = new ArrayList<LatLng>();
    for (LatLonPoint point : shapes) {
        LatLng latLngTemp = convertToLatLng(point);
        lineShapes.add(latLngTemp);
    }
    return lineShapes;
}
Also used : ArrayList(java.util.ArrayList) LatLng(com.amap.api.maps.model.LatLng) LatLonPoint(com.amap.api.services.core.LatLonPoint)

Example 47 with LatLng

use of com.amap.api.maps.model.LatLng in project DoraemonKit by didi.

the class DrivingRouteOverLay method getLatLngBounds.

@Override
protected LatLngBounds getLatLngBounds() {
    LatLngBounds.Builder b = LatLngBounds.builder();
    b.include(new LatLng(startPoint.latitude, startPoint.longitude));
    b.include(new LatLng(endPoint.latitude, endPoint.longitude));
    if (this.throughPointList != null && this.throughPointList.size() > 0) {
        for (int i = 0; i < this.throughPointList.size(); i++) {
            b.include(new LatLng(this.throughPointList.get(i).getLatitude(), this.throughPointList.get(i).getLongitude()));
        }
    }
    return b.build();
}
Also used : LatLngBounds(com.amap.api.maps.model.LatLngBounds) LatLng(com.amap.api.maps.model.LatLng) LatLonPoint(com.amap.api.services.core.LatLonPoint)

Example 48 with LatLng

use of com.amap.api.maps.model.LatLng in project DoraemonKit by didi.

the class DrivingRouteOverLay method addToMap.

/**
 * 添加驾车路线添加到地图上显示。
 */
public void addToMap() {
    initPolylineOptions();
    try {
        if (mAMap == null) {
            return;
        }
        if (mWidth == 0 || drivePath == null) {
            return;
        }
        mLatLngsOfPath = new ArrayList<LatLng>();
        tmcs = new ArrayList<TMC>();
        List<DriveStep> drivePaths = drivePath.getSteps();
        mPolylineOptions.add(startPoint);
        for (DriveStep step : drivePaths) {
            List<LatLonPoint> latlonPoints = step.getPolyline();
            List<TMC> tmclist = step.getTMCs();
            tmcs.addAll(tmclist);
            addDrivingStationMarkers(step, convertToLatLng(latlonPoints.get(0)));
            for (LatLonPoint latlonpoint : latlonPoints) {
                mPolylineOptions.add(convertToLatLng(latlonpoint));
                mLatLngsOfPath.add(convertToLatLng(latlonpoint));
            }
        }
        mPolylineOptions.add(endPoint);
        if (startMarker != null) {
            startMarker.remove();
            startMarker = null;
        }
        if (endMarker != null) {
            endMarker.remove();
            endMarker = null;
        }
        addStartAndEndMarker();
        addThroughPointMarker();
        if (isColorfulline && tmcs.size() > 0) {
            colorWayUpdate(tmcs);
        } else {
            showPolyline();
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : DriveStep(com.amap.api.services.route.DriveStep) LatLng(com.amap.api.maps.model.LatLng) TMC(com.amap.api.services.route.TMC) LatLonPoint(com.amap.api.services.core.LatLonPoint)

Example 49 with LatLng

use of com.amap.api.maps.model.LatLng in project spacecraft-android by JamesfChen.

the class MapActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    mapViewModel = ViewModelProviders.of(this).get(MapViewModel.class);
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        realRequestLocationForAmap(getIntent());
    }
    // 获取地图控件引用
    // mMapView = findViewById(R.id.map_view);
    // 在activity执行onCreate时执行mMapView.onCreate(savedInstanceState),创建地图
    // mMapView.onCreate(savedInstanceState);
    // AMap map = mMapView.getMap();
    textureMapView = findViewById(R.id.map_texture);
    textureMapView.onCreate(savedInstanceState);
    map = textureMapView.getMap();
    CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(// 参数1---要移动到的经纬度,参数2---地图的放缩级别zoom,参数3---地图倾斜度,参数4---地图的旋转角度
    new CameraPosition(myLocation, 4, 0, 0));
    map.moveCamera(cameraUpdate);
    myLocationStyle = new MyLocationStyle();
    // 设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
    // myLocationStyle.interval(2000);
    // 设置定位蓝点的Style
    // settings.setScrollGesturesEnabled(true);
    // settings.setAllGesturesEnabled(true);
    UiSettings settings = map.getUiSettings();
    settings.setMyLocationButtonEnabled(false);
    settings.setZoomControlsEnabled(false);
    settings.setRotateGesturesEnabled(false);
    // settings.setZoomInByScreenCenter(false);
    map.setMyLocationEnabled(true);
    map.setMyLocationStyle(myLocationStyle);
    // myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_SHOW);//只定位一次。
    // myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATE);//定位一次,且将视角移动到地图中心点。
    // myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW);//连续定位、且将视角移动到地图中心点,定位蓝点跟随设备移动。(1秒1次定位)
    // myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_MAP_ROTATE);//连续定位、且将视角移动到地图中心点,地图依照设备方向旋转,定位点会跟随设备移动。(1秒1次定位)
    // myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)默认执行此种模式。
    // //以下三种模式从5.1.0版本开始提供
    // myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER);//连续定位、蓝点不会移动到地图中心点,定位点依照设备方向旋转,并且蓝点会跟随设备移动。
    // 连续定位、蓝点不会移动到地图中心点,并且蓝点会跟随设备移动。
    myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER);
    // myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_MAP_ROTATE_NO_CENTER);//连续定位、蓝点不会移动到地图中心点,地图依照设备方向旋转,并且蓝点会跟随设备移动。
    myLocationStyle.showMyLocation(false);
    RecyclerView rv_cellinfos = findViewById(R.id.rv_cellinfos);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {

        @Override
        public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
            return makeMovementFlags(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
        }

        @Override
        public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
            int adapterPosition = viewHolder.getAdapterPosition();
            mapViewModel.delete(adapterPosition);
            stopAutoSmoothToEnd = true;
        }
    });
    itemTouchHelper.attachToRecyclerView(rv_cellinfos);
    MapAdapter adapter = new MapAdapter(this, map);
    rv_cellinfos.setAdapter(adapter);
    rv_cellinfos.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    SwipeRefreshLayout srf_cellinfos = findViewById(R.id.srf_cellinfos);
    bt_cellInfos = findViewById(R.id.bt_cellInfos);
    bt_cellInfos.setOnClickListener(v -> Toast.makeText(MapActivity.this, "是不是傻,不让点你还敢点", Toast.LENGTH_LONG).show());
    bt_mylocation = findViewById(R.id.bt_mylocation);
    bt_mylocation.setOnClickListener(v -> {
        Location myLocation = map.getMyLocation();
        double mylatitude = myLocation.getLatitude();
        double mylongitude = myLocation.getLongitude();
        Log.d(TAG, "mylocation: " + mylatitude + "," + mylongitude);
        this.myLocation = new LatLng(mylatitude, mylongitude);
        map.animateCamera(CameraUpdateFactory.newCameraPosition(// 参数1---要移动到的经纬度,参数2---地图的放缩级别zoom,参数3---地图倾斜度,参数4---地图的旋转角度
        new CameraPosition(this.myLocation, 9, 0, 0)));
    });
    bt_import = findViewById(R.id.bt_import);
    bt_import.setOnClickListener(view -> {
        if (is_import) {
            Toast.makeText(MapActivity.this, "蛋已经领取啦,咋还想领", Toast.LENGTH_SHORT).show();
            return;
        }
        is_import = true;
        Toast.makeText(MapActivity.this, "彩蛋,正在导入数据", Toast.LENGTH_SHORT).show();
        iLbsApiClient.sendImportMockJson();
    });
    mapViewModel.getAllLbsDatas().observe(this, p -> {
        bt_cellInfos.setText("不许点击喔:" + p.size());
        adapter.submitList(p);
        if (!stopAutoSmoothToEnd && p.size() > 5) {
            rv_cellinfos.smoothScrollToPosition(p.size() - 1);
        }
        stopAutoSmoothToEnd = false;
    });
    mapViewModel.getNeedUploadDatas().observe(this, p -> {
        if (p == null || p.size() == 0)
            return;
        Log.d(TAG, "getNeedUploadDatas: " + p.size());
        for (int i = 0; i < p.size(); i++) {
            LBS lbs = p.get(i);
        // ReportApi.reportLocation(auth, lbs, new ReportApi.Callback() {
        // @Override
        // public void onFailure() {
        // }
        // 
        // @Override
        // public void onResponse() {
        // lbs.setNeedUpload(false);
        // mapViewModel.update(lbs);
        // }
        // });
        }
    });
    srf_cellinfos.setOnRefreshListener(() -> srf_cellinfos.setRefreshing(false));
}
Also used : MyLocationStyle(com.amap.api.maps.model.MyLocationStyle) UiSettings(com.amap.api.maps.UiSettings) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) SuppressLint(android.annotation.SuppressLint) MapViewModel(com.jamesfchen.map.model.MapViewModel) CameraPosition(com.amap.api.maps.model.CameraPosition) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) RecyclerView(androidx.recyclerview.widget.RecyclerView) LatLng(com.amap.api.maps.model.LatLng) CameraUpdate(com.amap.api.maps.CameraUpdate) LBS(com.jamesfchen.map.model.LBS) AMapLocation(com.amap.api.location.AMapLocation) Location(android.location.Location) AppLocation(com.jamesfchen.map.model.AppLocation)

Aggregations

LatLng (com.amap.api.maps.model.LatLng)49 LatLonPoint (com.amap.api.services.core.LatLonPoint)15 MarkerOptions (com.amap.api.maps.model.MarkerOptions)9 ArrayList (java.util.ArrayList)7 LatLngBounds (com.amap.api.maps.model.LatLngBounds)6 Marker (com.amap.api.maps.model.Marker)6 CameraUpdate (com.amap.api.maps.CameraUpdate)5 Bitmap (android.graphics.Bitmap)4 Point (android.graphics.Point)4 CameraPosition (com.amap.api.maps.model.CameraPosition)4 PolylineOptions (com.amap.api.maps.model.PolylineOptions)4 SuppressLint (android.annotation.SuppressLint)3 TextView (android.widget.TextView)3 Polyline (com.amap.api.maps.model.Polyline)3 Location (android.location.Location)2 View (android.view.View)2 BounceInterpolator (android.view.animation.BounceInterpolator)2 Interpolator (android.view.animation.Interpolator)2 ImageView (android.widget.ImageView)2 BindView (butterknife.BindView)2