在 Ionic 3 上使用 MapQuest 方向路由时出现运行时异常

问题描述

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

这些是导入:

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"

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

  crossorigin=""/>

<script src="https://unpkg.com/[email protected]/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,NY 10006',});

错误如下:

ERROR Error: Uncaught (in promise): 
TypeError: this._rawPxBounds is undefined _updateBounds@https://unpkg.com/[email protected]/dist/leaflet.js:5:79584 
setStyle@https://unpkg.com/[email protected]/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 的新手,所以不确定出了什么问题。有什么想法吗?

解决方法

我去掉了 [email protected][email protected] 的导入,只导入了 [email protected]。现在可以正常使用了。

<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"/>