业务需要获取线路,发现原生map是不支持的???
通过uni.createMapContext获取map上下文对象,在通过$getAppMap()获取plus.map对象,进行线路绘制。
但是貌似不可用???
或者有其他的方式可以实现线路规划的吗?
<template>
<view>
<view class="page-body">
<view class="page-section page-section-gap">
<map id="map1" style="width: 100%; height: 1334px;" :latitude="latitude" :longitude="longitude">
</map>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
latitude: 39.909,
longitude: 116.39742,
}
},
onReady() {
var nmap = uni.createMapContext("navmap", this);
var map = nmap.$getAppMap();
var routeObj = new plus.maps.Route(new plus.maps.Point(121.618622, 38.91459), new plus.maps.Point(116.397454,
39.909178))
console.log(JSON.stringify(routeObj))
var b = map.addOverlay(routeObj)
console.log("是否添加成功:" + b)
var searchObj = new plus.maps.Search(map);
searchObj.onRouteSearchComplete = function(state, result) {
console.log("onRouteSearchComplete: " + state + " , " + result.routeNumber);
if (state == 0) {
if (result.routeNumber <= 0) {
alert("没有检索到结果");
}
for (var i = 0; i < result.routeNumber; i++) {
console.log(JSON.stringify(result.getRoute(i)))
map.addOverlay(result.getRoute(i));
}
} else {
alert("检索失败");
}
}
searchObj.transitSearch("天安门", "大钟寺", "北京");
},
methods: {
}
}
</script>
<style>
</style>
1***@qq.com
$getAppMap 只有app能用
2020-08-21 15:43