首页 > 解决方案 > 在 Ionic 3 上使用 MapQuest 方向路由时出现运行时异常

问题描述

我正在使用 Ionic 3 框架,我可以成功生成地图,但在使用该L.mapquest.directions().route()函数时收到运行时错误。

这些是进口:

<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"

  integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="

  crossorigin=""/>

<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"

  integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="

  crossorigin=""></script>

<script src="https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest-core.js"></script>

<link type="text/css" rel="stylesheet" href="https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest-core.css"/>

这些是代码:

L.mapquest.key = MapQuestKey;
      this.map = L.mapquest.map('map', {
        center: [lat, lng],
        layers: L.mapquest.tileLayer('map'),
        zoom: 13
      });
L.mapquest.directions().route({

        start: '350 5th Ave, New York, NY 10118',

        end: 'One Liberty Plaza, New York, NY 10006',

});

错误如下所示:

ERROR Error: Uncaught (in promise): 
TypeError: this._rawPxBounds is undefined _updateBounds@https://unpkg.com/leaflet@1.7.1/dist/leaflet.js:5:79584 
setStyle@https://unpkg.com/leaflet@1.7.1/dist/leaflet.js:5:75174 
setPathStyle@https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest-core.js:6:161888
updateRibbonWidth@https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest-core.js:6:163063

Mapquest 的新手,所以不确定出了什么问题。有任何想法吗?

标签: typescriptionic-frameworkleafletmapquest

解决方案


我从 Leaflet@1.7.1 和 mapquest-core@1.3.2 中删除了导入,只导入了 mapquest.js@1.3.2。它现在可以正常运行。

<script src="https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest.js"></script>

<link type="text/css" rel="stylesheet" href="https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest.css"/>

推荐阅读