|
|
|
@ -1,11 +1,14 @@ |
|
|
|
package com.yunqiinnovation.amap_service |
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.os.Bundle |
|
|
|
import android.util.Log |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
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.enums.PathPlanningStrategy |
|
|
|
import com.amap.api.navi.model.AMapCalcRouteResult |
|
|
|
import com.amap.api.navi.model.AMapLaneInfo |
|
|
|
import com.amap.api.navi.model.AMapModelCross |
|
|
|
@ -18,24 +21,35 @@ import com.amap.api.navi.model.AMapServiceAreaInfo |
|
|
|
import com.amap.api.navi.model.AimLessModeCongestionInfo |
|
|
|
import com.amap.api.navi.model.AimLessModeStat |
|
|
|
import com.amap.api.navi.model.NaviInfo |
|
|
|
import com.amap.api.navi.model.NaviLatLng |
|
|
|
import com.yunqiinnovation.amap_service.NavigationService.Companion.sharedNavi |
|
|
|
|
|
|
|
class NavigationActivity : AppCompatActivity(), AMapNaviListener, AMapNaviViewListener { |
|
|
|
private lateinit var naviView: AMapNaviView |
|
|
|
private var navi: AMapNavi? = null |
|
|
|
|
|
|
|
private lateinit var context: Context |
|
|
|
private var startpos:String = ""; |
|
|
|
private var endpos:String = ""; |
|
|
|
private var ntype:String = ""; |
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
setContentView(R.layout.activity_navigation) |
|
|
|
|
|
|
|
context = this |
|
|
|
// 初始化导航视图 |
|
|
|
naviView = findViewById(R.id.navi_view) |
|
|
|
naviView.onCreate(savedInstanceState) |
|
|
|
naviView.setAMapNaviViewListener(this) |
|
|
|
|
|
|
|
startpos = intent.getStringExtra("startpos").toString() |
|
|
|
endpos = intent.getStringExtra("endpos").toString() |
|
|
|
ntype = intent.getStringExtra("ntype").toString() |
|
|
|
Log.i("NavigationActivity", "onCreate $startpos $endpos $ntype") |
|
|
|
navi = NavigationService.sharedNavi |
|
|
|
if (navi == null) { |
|
|
|
finish() // 服务未启动,退出 |
|
|
|
return |
|
|
|
navi = AMapNavi.getInstance(context).apply { |
|
|
|
setUseInnerVoice(true) |
|
|
|
setBroadcastMode(1) |
|
|
|
} |
|
|
|
} |
|
|
|
navi?.addAMapNaviListener(this); |
|
|
|
|
|
|
|
@ -53,9 +67,13 @@ class NavigationActivity : AppCompatActivity(), AMapNaviListener, AMapNaviViewLi |
|
|
|
} |
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
|
super.onDestroy() |
|
|
|
naviView.onDestroy() |
|
|
|
navi?.stopNavi() |
|
|
|
navi?.removeAMapNaviListener(this); |
|
|
|
AMapNavi.destroy() |
|
|
|
NavigationServiceHelper.startNavigation(context,"stop") |
|
|
|
naviView.onDestroy() |
|
|
|
super.onDestroy() |
|
|
|
Log.i("NavigationActivity", "liwei------------------- onDestroy!") |
|
|
|
} |
|
|
|
|
|
|
|
override fun onInitNaviFailure() { |
|
|
|
@ -63,6 +81,25 @@ class NavigationActivity : AppCompatActivity(), AMapNaviListener, AMapNaviViewLi |
|
|
|
} |
|
|
|
|
|
|
|
override fun onInitNaviSuccess() { |
|
|
|
Log.i("NavigationActivity", "onInitNaviSuccess!") |
|
|
|
// 起点 |
|
|
|
val startParts: List<String> = startpos.split(",") |
|
|
|
val startLng = startParts[0].toDouble() |
|
|
|
val startLat = startParts[1].toDouble() |
|
|
|
|
|
|
|
// 终点 |
|
|
|
val endParts: List<String> = endpos.split(",") |
|
|
|
val endLng = endParts[0].toDouble() |
|
|
|
val endLat = endParts[1].toDouble() |
|
|
|
|
|
|
|
val startList: MutableList<NaviLatLng> = ArrayList() |
|
|
|
val endList: MutableList<NaviLatLng> = ArrayList() |
|
|
|
startList.add(NaviLatLng(startLat, startLng)) |
|
|
|
endList.add(NaviLatLng(endLat, endLng)) |
|
|
|
val success = navi?.calculateDriveRoute(startList, endList, null, PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_DEFAULT); |
|
|
|
if (!success!!) { |
|
|
|
Log.e("NavigationActivity", "路径规划请求失败") |
|
|
|
} |
|
|
|
// TODO("Not yet implemented") |
|
|
|
} |
|
|
|
|
|
|
|
@ -167,6 +204,7 @@ class NavigationActivity : AppCompatActivity(), AMapNaviListener, AMapNaviViewLi |
|
|
|
} |
|
|
|
|
|
|
|
override fun onCalculateRouteSuccess(p0: IntArray?) { |
|
|
|
navi?.startNavi(1); |
|
|
|
// TODO("Not yet implemented") |
|
|
|
} |
|
|
|
|
|
|
|
@ -212,7 +250,7 @@ class NavigationActivity : AppCompatActivity(), AMapNaviListener, AMapNaviViewLi |
|
|
|
} |
|
|
|
|
|
|
|
override fun onNaviCancel() { |
|
|
|
finish() |
|
|
|
finishAndRemoveTask() |
|
|
|
// TODO("Not yet implemented") |
|
|
|
} |
|
|
|
|
|
|
|
|