mapsjs-core.js:27 uncatch TypeError: 无法读取 undefined 的属性(读取 '0')



我需要的帮助

我使用这里的地图api,我试图显示城市周围的轮廓,这是一个错误

const shape = res.response.isoline[0].component[0].shape.map(z => z.split(','));

这是完整的代码

const requestIsolineShape=options=>{const params={'模式':CCD_ 1,"启动":CCD_ 2,'range':选项.range,"rangetype":选项。rangetype,‘出发’:CCD_ 3,};

return new Promise((resolve,reject(=>{router.calculateIsoline(params,res=>{const shape=res.response.isoline[0]。component[0]。shape.map(z=>z.split(','((;解析(形状(;},err=>拒绝(错误();});};

请在浏览器的控制台("网络"选项卡(中仔细检查哪些参数被发送到路由隔离线服务,并检查响应。

看来您正在使用路由API 7.2版,然后请在https://refclient.ext.here.com/-点击";新标签+";

如果您切换到路由API的新版本8并使用直接集成到JS API的此服务,则会获得更好的解决方案:https://developer.here.com/documentation/maps/3.1.30.7/api_reference/H.service.RoutingService8.html#calculateIsoline

示例:

let routingParams = {
'routingMode': 'fast',
'transportMode': 'car',
'origin':'52.5,13.4',
'range[type]': 'time',
'range[values]': '900',
};
// Define a callback function to process the routing response
let onResult = function(result) {
if (result.isolines.length) {
result.isolines[0].polygons.forEach((polygon) => {
// Create a linestring to use as a point source for the isoline
const linestring = H.geo.LineString.fromFlexiblePolyline(polygon.outer);
// Create a polygon and a marker representing the isoline
const isolinePolygon = new H.map.Polygon(linestring, {
style: { strokeColor: 'blue', lineWidth: 3 }
});
// Create a marker for the start point
const isolineCenter = new H.map.Marker(result.departure.place.location);
// Add the polygon and marker to the map
map.addObjects([isolinePolygon, isolineCenter]);
// Center and zoom the map so that the whole isoline polygon is
// in the viewport
map.getViewModel().setLookAtData({bounds: isolinePolygon.getBoundingBox()});
});
}
};
// Assumption: the platform is instantiated.
// Get an instance of the routing service
let router = platform.getRoutingService(null, 8);
// Call the Isoline Routing API to calculate an isoline
router.calculateIsoline(
routingParams,
onResult,
console.error
);

v8的游乐场:https://demo.routing.ext.here.com/

最新更新