Merge branch 'main' of https://github.com/MADAO-LUV/ManGoWalk
This commit is contained in:
@@ -1,29 +1,37 @@
|
||||
package com.example.mangowalking;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.amap.api.location.AMapLocationClient;
|
||||
import com.amap.api.location.AMapLocationClientOption;
|
||||
import com.amap.api.location.AMapLocationListener;
|
||||
import com.amap.api.maps.AMapException;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.Poi;
|
||||
import com.amap.api.navi.AMapNavi;
|
||||
import com.amap.api.navi.AMapNaviListener;
|
||||
import com.amap.api.navi.AMapNaviView;
|
||||
import com.amap.api.navi.AMapNaviViewListener;
|
||||
import com.amap.api.navi.AmapNaviPage;
|
||||
import com.amap.api.navi.AmapNaviParams;
|
||||
import com.amap.api.navi.AmapNaviType;
|
||||
import com.amap.api.navi.AmapPageType;
|
||||
import com.amap.api.navi.ParallelRoadListener;
|
||||
import com.amap.api.navi.enums.AMapNaviParallelRoadStatus;
|
||||
import com.amap.api.navi.enums.NaviType;
|
||||
import com.amap.api.navi.enums.TransportType;
|
||||
import com.amap.api.navi.enums.TravelStrategy;
|
||||
import com.amap.api.navi.model.*;
|
||||
import com.example.mangowalking.utils.TTSController;
|
||||
import com.google.android.filament.View;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -32,38 +40,109 @@ import java.util.List;
|
||||
public class GuideMap extends AppCompatActivity implements AMapNaviListener, AMapNaviViewListener, ParallelRoadListener {
|
||||
private static final String TAG = "GuideMap";
|
||||
private AMapNaviView mNaviView; // 对应DEMO mAMapNaviView;
|
||||
private AMapNavi mNavi; // mAMapNavi;
|
||||
private AMapNavi mAMapNavi; // mAMapNavi;
|
||||
|
||||
protected TTSController mTtsManager;
|
||||
private NaviLatLng mStartPoint; // 起点
|
||||
private NaviLatLng mEndPoint; // 终点
|
||||
|
||||
//终点坐标
|
||||
private double endLat,endLon; //终点坐标
|
||||
|
||||
private List<NaviLatLng> mWayPoints = new ArrayList<>(); // 途经点
|
||||
|
||||
protected final List<NaviLatLng> sList = new ArrayList<NaviLatLng>();
|
||||
protected final List<NaviLatLng> eList = new ArrayList<NaviLatLng>();
|
||||
protected List<NaviLatLng> mWayPointList = new ArrayList<NaviLatLng>();
|
||||
//与定位相关
|
||||
private AMapLocationClient mapLocationClient;
|
||||
private AMapLocationClientOption mLocationOption;
|
||||
private boolean isAutoStartLocation = false;
|
||||
|
||||
private AmapNaviType currentNaviType = AmapNaviType.WALK;
|
||||
private NaviLatLng end;
|
||||
private TextView tvRouteInfo;
|
||||
private Button btnStartNavi;
|
||||
private Button btnSwitchMode;
|
||||
|
||||
@SuppressLint("MissingInflatedId")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// mNavi.setIsNaviTravelView(true);
|
||||
setContentView(R.layout.activity_guide_map);
|
||||
// 1. 初始化导航组件
|
||||
mNaviView = findViewById(R.id.naviView);
|
||||
mNaviView.onCreate(savedInstanceState);
|
||||
|
||||
// 获取传入的终点经纬度
|
||||
Intent intent = getIntent();
|
||||
endLat = intent.getDoubleExtra("end_lat", 0);
|
||||
endLon = intent.getDoubleExtra("end_lon", 0);
|
||||
Log.d("GuideMap", "收到终点坐标: lat=" + endLat + ", lon=" + endLon);
|
||||
Log.d("GuideMap", "接收到坐标:" + endLat + "," + endLon);
|
||||
|
||||
if (endLat < 1 || endLon < 1) {
|
||||
Toast.makeText(this, "终点坐标可能异常", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
end = new NaviLatLng(endLat,endLon);
|
||||
startNaviToDestination(currentNaviType);
|
||||
//
|
||||
// mNaviView = findViewById(R.id.naviView);
|
||||
// mNaviView.onCreate(savedInstanceState);
|
||||
//
|
||||
// mTtsManager = TTSController.getInstance(getApplicationContext());
|
||||
// mTtsManager.init();
|
||||
// mTtsManager.setTTSType(TTSController.TTSType.SYSTEMTTS);
|
||||
// try {
|
||||
// AMapNavi.getInstance(this).calculateWalkRoute(null,end);
|
||||
// } catch (AMapException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
|
||||
try {
|
||||
mNavi = AMapNavi.getInstance(getApplicationContext());
|
||||
AMapNavi.getInstance(this).calculateWalkRoute(end);
|
||||
mAMapNavi = AMapNavi.getInstance(getApplicationContext());
|
||||
mAMapNavi.setUseInnerVoice(true,false);
|
||||
AMapNavi.setTtsPlaying(true);
|
||||
} catch (AMapException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
mAMapNavi.addAMapNaviListener(mTtsManager);
|
||||
mAMapNavi.playTTS("主人你好呀", false);
|
||||
|
||||
// mAMapNavi.startNavi(NaviType.EMULATOR);
|
||||
//以上为新添加的 不知道怎么处理
|
||||
|
||||
// try {
|
||||
// mAMapNavi = AMapNavi.getInstance(getApplicationContext());
|
||||
// } catch (AMapException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// mAMapNavi.addAMapNaviListener(this);
|
||||
// mAMapNavi.addAMapNaviListener(mTtsManager);
|
||||
//
|
||||
// // 🚩 设置为骑/步行视图(重要)
|
||||
// mAMapNavi.setIsNaviTravelView(true);
|
||||
//
|
||||
// // 🚶 步行路线规划(起点为空)——无起点规划
|
||||
// NaviLatLng end = new NaviLatLng(endLat, endLon);
|
||||
// mAMapNavi.calculateWalkRoute(end); // 或 mAMapNavi.calculateRideRoute(end);
|
||||
//
|
||||
// // 初始化界面控件
|
||||
// tvRouteInfo = findViewById(R.id.tvRouteInfo);
|
||||
// btnStartNavi = findViewById(R.id.btnStartNavi);
|
||||
// btnSwitchMode = findViewById(R.id.btnSwitchMode);
|
||||
// // 切换模式按钮
|
||||
// btnSwitchMode.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// if (currentNaviType == AmapNaviType.WALK) {
|
||||
// currentNaviType = AmapNaviType.DRIVER;
|
||||
// } else {
|
||||
// currentNaviType = AmapNaviType.WALK;
|
||||
// }
|
||||
// updateRouteInfoText();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// // 开始导航按钮
|
||||
// btnStartNavi.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// startNaviToDestination(currentNaviType);
|
||||
// }
|
||||
// });
|
||||
|
||||
// 2. 设置导航监听器
|
||||
mNavi.addAMapNaviListener(this);
|
||||
mNaviView.setAMapNaviViewListener(new AMapNaviViewListener() {
|
||||
@Override
|
||||
public void onNaviSetting() {
|
||||
@@ -122,12 +201,12 @@ public class GuideMap extends AppCompatActivity implements AMapNaviListener, AMa
|
||||
}
|
||||
// 处理导航视图事件...
|
||||
});
|
||||
mNaviView.setNaviMode(mNaviView.NORTH_UP_MODE);
|
||||
initLocation();
|
||||
|
||||
// 3. 添加途经点(可选)
|
||||
// mWayPoints.add(new NaviLatLng(39.993706, 116.400865));
|
||||
//初始化定位
|
||||
// initLocation();
|
||||
// mNaviView.setNaviMode(mNaviView.NORTH_UP_MODE);
|
||||
}
|
||||
@Override
|
||||
public void onNaviSetting() {
|
||||
@@ -223,6 +302,22 @@ public class GuideMap extends AppCompatActivity implements AMapNaviListener, AMa
|
||||
|
||||
}
|
||||
|
||||
private void updateRouteInfoText() {
|
||||
String modeText = currentNaviType == AmapNaviType.WALK ? "步行模式" : "公交模式";
|
||||
tvRouteInfo.setText("当前导航模式:" + modeText);
|
||||
}
|
||||
|
||||
private void startNaviToDestination(AmapNaviType naviType) {
|
||||
Poi end = new Poi("目的地", new LatLng(endLat, endLon), null);
|
||||
AmapNaviParams params = new AmapNaviParams(null, null, end, naviType, AmapPageType.ROUTE);
|
||||
params.setUseInnerVoice(true);
|
||||
AmapNaviPage.getInstance().showRouteActivity(getApplicationContext(), params, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
@@ -238,14 +333,25 @@ public class GuideMap extends AppCompatActivity implements AMapNaviListener, AMa
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
// super.onDestroy();
|
||||
// mNaviView.onDestroy();
|
||||
// //since 1.6.0 不再在naviview destroy的时候自动执行AMapNavi.stopNavi();请自行执行
|
||||
// if (mAMapNavi!=null){
|
||||
// mAMapNavi.stopNavi();
|
||||
// mAMapNavi.destroy();
|
||||
// }
|
||||
super.onDestroy();
|
||||
mNaviView.onDestroy();
|
||||
//since 1.6.0 不再在naviview destroy的时候自动执行AMapNavi.stopNavi();请自行执行
|
||||
if (mNavi!=null){
|
||||
mNavi.stopNavi();
|
||||
mNavi.destroy();
|
||||
// if(mTtsManager != null)
|
||||
// {
|
||||
// mTtsManager.stopSpeaking();
|
||||
// mTtsManager.destroy();
|
||||
// }
|
||||
if(mAMapNavi != null)
|
||||
{
|
||||
// mAMapNavi.removeAMapNaviListener(mTtsManager);
|
||||
mAMapNavi.stopNavi();
|
||||
}
|
||||
|
||||
mNaviView.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -257,8 +363,8 @@ public class GuideMap extends AppCompatActivity implements AMapNaviListener, AMa
|
||||
@Override
|
||||
public void onInitNaviSuccess() {
|
||||
//这里无需super 因为我是直接在父类上直接写
|
||||
mNavi.setTravelInfo(new AMapTravelInfo(TransportType.Walk));
|
||||
mNavi.calculateWalkRoute(new NaviLatLng(39.925846, 116.435765), new NaviLatLng(39.925846, 116.532765));
|
||||
mAMapNavi.setTravelInfo(new AMapTravelInfo(TransportType.Walk));
|
||||
mAMapNavi.calculateWalkRoute(null, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -273,7 +379,7 @@ public class GuideMap extends AppCompatActivity implements AMapNaviListener, AMa
|
||||
|
||||
@Override
|
||||
public void onLocationChange(AMapNaviLocation aMapNaviLocation) {
|
||||
|
||||
aMapNaviLocation.getCoord();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -413,7 +519,12 @@ public class GuideMap extends AppCompatActivity implements AMapNaviListener, AMa
|
||||
|
||||
@Override
|
||||
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
|
||||
mNavi.startNavi(NaviType.GPS);
|
||||
try {
|
||||
AMapNavi.getInstance(this).startNavi(NaviType.GPS);
|
||||
AMapNavi.getInstance(this.getApplicationContext()).setIsNaviTravelView(true);
|
||||
} catch (AMapException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user