use of com.amap.api.maps.model.LatLng in project uav_mobile_app by jiushuokj.
the class MainActivity method markWaypoint.
private void markWaypoint(final LatLng point) {
// Create MarkerOptions object
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(point);
markerOptions.draggable(true);
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE));
Marker marker = aMap.addMarker(markerOptions);
// 画线
List<LatLng> latLngs = new ArrayList<LatLng>();
if (mMarkers.size() == 0) {
LatLng homeLatLng = getHomeLatLng();
Log.i(TAG, "home坐标:" + homeLatLng.latitude + "---" + homeLatLng.longitude);
latLngs.add(homeLatLng);
} else {
latLngs.add(mMarkers.get(mMarkers.size() - 1).getPosition());
}
latLngs.add(marker.getPosition());
for (LatLng latLng : latLngs) {
Log.i(TAG, "画线坐标: " + latLng);
}
Polyline polyline = aMap.addPolyline((new PolylineOptions()).add(latLngs.get(0), latLngs.get(1)).width(5).setDottedLine(// 虚线
true).color(Color.BLUE));
mMarkers.put(mMarkers.size(), marker);
mPolylines.put(mPolylines.size(), polyline);
setSelectedMarker(marker);
}
use of com.amap.api.maps.model.LatLng in project uav_mobile_app by jiushuokj.
the class MainActivity method cameraUpdate.
private void cameraUpdate() {
// 坐标转换
// LatLng pos = new LatLng(droneLocationLat, droneLocationLng);
LatLng pos = CoordinateTransUtils.getGDLatLng(droneLocationLat, droneLocationLng);
float zoomlevel = (float) 18.0;
CameraUpdate cu = CameraUpdateFactory.newLatLngZoom(pos, zoomlevel);
aMap.moveCamera(cu);
}
use of com.amap.api.maps.model.LatLng in project uav_mobile_app by jiushuokj.
the class MainActivity method loadWaypointMission.
private void loadWaypointMission() {
if (mMarkers.size() == 0) {
setResultToToast("地图上没有标记!");
return;
}
// 将mMarkers中的点转换成航点的列表
if (waypointMissionBuilder == null) {
waypointMissionBuilder = new WaypointMission.Builder();
}
List<Waypoint> waypointList = new ArrayList<>();
for (int i = 0; i < mMarkers.size(); i++) {
// 坐标转换
LatLng djiLatLng = CoordinateTransUtils.getDJILatLng(mMarkers.get(i).getPosition().latitude, mMarkers.get(i).getPosition().longitude);
Waypoint waypoint = new Waypoint(djiLatLng.latitude, djiLatLng.longitude, altitude);
waypointList.add(waypoint);
}
waypointMissionBuilder.finishedAction(mFinishedAction).headingMode(mHeadingMode).autoFlightSpeed(mSpeed).maxFlightSpeed(mSpeed).flightPathMode(WaypointMissionFlightPathMode.NORMAL).waypointList(waypointList).waypointCount(waypointList.size());
if (waypointMissionOperator == null) {
waypointMissionOperator = DJISDKManager.getInstance().getMissionControl().getWaypointMissionOperator();
}
Log.i(TAG, "loadWaypointMission: altitude-->" + altitude + "\nmFinishedAction-->" + mFinishedAction + "\nmHeadingMode-->" + mHeadingMode + "\nmSpeed-->" + mSpeed);
DJIError error = waypointMissionOperator.loadMission(waypointMissionBuilder.build());
if (error == null) {
setResultToToast("保存任务成功!");
delete.setEnabled(false);
clear.setEnabled(false);
upload.setEnabled(true);
start.setEnabled(false);
pause.setEnabled(false);
resume.setEnabled(false);
stop.setEnabled(false);
} else {
setResultToToast("保存任务失败:\n " + error.getDescription());
}
}
use of com.amap.api.maps.model.LatLng in project uav_mobile_app by jiushuokj.
the class MainActivity method deleteSelectedMarker.
/**
* 删除地图上当前选定的标记
* 1.mMarkers中删除该点,地图上删除点,并且在mMarkers中将其后面的点往前移动
* 2.mPolyLines中删除该点有关的两条线,地图也删除,并且将其前后两点相连
* 3.选中改点的下一点为当前标记
*/
private void deleteSelectedMarker() {
if (selectedMarker == null) {
setResultToToast("当前没有选中标记");
return;
}
if (mMarkers.size() == 0) {
setResultToToast("当前地图上没有标记");
return;
}
final Integer selectedIndex = getKey(mMarkers, selectedMarker);
if (selectedIndex < 0) {
setResultToToast("选中的标记不在mMarker中");
return;
}
selectedMarker.remove();
for (int i = selectedIndex; i < mMarkers.size() - 1; i++) {
mMarkers.put(i, mMarkers.get(i + 1));
}
mMarkers.remove(mMarkers.size() - 1);
if (mPolylines.size() == 0) {
setResultToToast("当前地图上没有连线");
} else if (mPolylines.size() == 1) {
// 只有一个点
for (Integer integer : mPolylines.keySet()) {
mPolylines.get(integer).remove();
mPolylines.remove(integer);
}
} else if (selectedIndex == mPolylines.size() - 1) {
// 最后一个点
mPolylines.get(selectedIndex).remove();
mPolylines.remove(selectedIndex);
setSelectedMarker(mMarkers.get(selectedIndex - 1));
} else {
LatLng homeLatLng = getHomeLatLng();
Polyline newPolyline = aMap.addPolyline((new PolylineOptions()).add(selectedIndex == 0 ? homeLatLng : mMarkers.get(selectedIndex - 1).getPosition(), mMarkers.get(selectedIndex).getPosition()).width(5).setDottedLine(// 虚线
true).color(Color.BLUE));
Polyline selectedPolyline = mPolylines.get(selectedIndex);
selectedPolyline.remove();
Polyline nextSelectedPolyline = mPolylines.get(selectedIndex + 1);
nextSelectedPolyline.remove();
mPolylines.put(selectedIndex, newPolyline);
for (int i = selectedIndex + 1; i < mPolylines.size() - 1; i++) {
mPolylines.put(i, mPolylines.get(i + 1));
}
mPolylines.remove(mPolylines.size() - 1);
setSelectedMarker(mMarkers.get(selectedIndex));
}
for (Integer integer : mMarkers.keySet()) {
Log.i(TAG, "deleteSelectedMarker: 第" + integer + "个标记" + mMarkers.get(integer).getPosition());
}
for (Integer integer : mPolylines.keySet()) {
Log.i(TAG, "deleteSelectedMarker: 第" + integer + "条线" + mPolylines.get(integer).getPoints());
}
}
use of com.amap.api.maps.model.LatLng in project DoraemonKit by didi.
the class MockGPSTaskManager method startGpsMockTask.
public Observable<Location> startGpsMockTask() {
return Observable.interval(0, PERIOD_UNIT, TimeUnit.MILLISECONDS, Schedulers.io()).filter(new Predicate<Long>() {
@Override
public boolean test(Long aLong) throws Exception {
boolean periodMatched = (aLong % getPeriodLevel()) == 0;
return checkMockLocationState() && periodMatched;
// return checkMockLocationState();
}
}).map(new Function<Long, Long>() {
@Override
public Long apply(@NonNull Long aLong) throws Exception {
return mProgressIndex++;
}
}).takeWhile(new Predicate<Long>() {
@Override
public boolean test(Long aLong) throws Exception {
return !mSkip && taskInfoData != null && aLong < taskInfoData.mockGPSItems.size();
}
}).observeOn(AndroidSchedulers.mainThread()).map(new Function<Long, Location>() {
private Location mLastLocation;
@Override
public Location apply(Long aLong) throws Exception {
MockGPSTaskData.MockGPSItem mockGPSItem = taskInfoData.mockGPSItems.get(aLong.intValue());
// 轨迹模拟
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(mockGPSItem.lat);
location.setLongitude(mockGPSItem.lng);
location.setAccuracy(mockGPSItem.accuracy.floatValue());
location.setSpeed(mockGPSItem.speed.floatValue());
location.setBearing(mockGPSItem.bearing);
LogUtils.v(TAG, "⚠️模拟定位:" + location + " index: " + aLong + " TaskInfoData: " + taskInfoData);
float calculateLineDistance = (location == null || mLastLocation == null) ? -1 : AMapUtils.calculateLineDistance(new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude()), new LatLng(location.getLatitude(), location.getLongitude()));
if (calculateLineDistance < 0) {
LogUtils.v(TAG, "⚠️模拟定位:" + location + " index: " + aLong + " TaskInfoData: " + taskInfoData);
} else if (calculateLineDistance > 100) {
LogUtils.w(TAG, "⚠️模拟定位: 跳动距离:" + calculateLineDistance + " " + location + " index: " + aLong + " TaskInfoData: " + taskInfoData);
} else {
LogUtils.v(TAG, "⚠️模拟定位: 跳动距离:" + calculateLineDistance + " " + location + " index: " + aLong + " TaskInfoData: " + taskInfoData);
}
mLastLocation = location;
// GpsMockManager.getInstance().mockLocationWithNotify(location);
return location;
}
}).doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
LogUtils.d(TAG, "mock 子任务异常 " + taskInfoData + " " + throwable + "]");
}
});
}
Aggregations