Javascript,将地址字符串传递给MapQuest API无效

时间:2018-06-01 14:20:48

标签: javascript api mapquest

我正在动态地将地址列表传递给字符串变量,并希望使用MapQuest API在地图上绘制它们。但是当我将这些地址传递给我的函数时,我收到了一个错误。

mq-routing.js?key=jP…M0C6qxa2BKpuAhqZ:44 Uncaught TypeError: Cannot read property 'length' of undefined at e.route (mq-routing.js?key=jP…M0C6qxa2BKpuAhqZ:44) at map.cfm:153 ​ 看起来它并不喜欢我传递地址字符串的方式。

 '<script type="text/javascript" language="JavaScript">

var jsmyRouteStops="{locations: ['100 W Atlantic Blvd Pompano Beach FL, 33060-6099','50 W Atlantic Blvd, BL Pompano Beach FL, 33060-6002','111 N Pompano Beach Blvd, BL Pompano Beach FL, 33062-5703','201 N Ocean Blvd, BL Pompano Beach FL, 33062-5104','501 N Riverside Dr Pompano Beach FL, 33062-4702','2809 NW 2nd St Pompano Beach FL, 33069-2523','3095 N Course Dr Pompano Beach FL, 33069-3300','2600 S Course Dr Pompano Beach FL, 33069-3900','[1401 - 1477] SW 26th Ave Pompano Beach FL, 33069-4315','705 Gardens Dr Pompano Beach FL, 33069-0945']}"; new Array();

    var map,
    dir;

    map = L.map('map', {
        layers: MQ.mapLayer(),
        center: [ 26.230735, -80.124932 ],
        zoom: 15
    });

    dir = MQ.routing.directions();

    dir.route(jsmyRouteStops.trim());

    map.addLayer(MQ.routing.routeLayer({
        directions: dir,
        fitBounds: true
    }));

</script>

我在这里应该做些什么吗?

dir.route(jsmyRouteStops.trim());

非常感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

当我删除jsmyRouteStops周围的引号时,它对我有用。

var jsmyRouteStops = {locations:[&#39; 100 W Atlantic Blvd Pompano Beach FL,33060-6099&#39; 50 W Atlantic Blvd,BL Pompano Beach FL,33060-6002&#39;, &#39; 111 N Pompano Beach Blvd,BL Pompano Beach FL,33062-5703&#39; 201 N Ocean Blvd,BL Pompano Beach FL,33062-5104&#39; 501 N Riverside Dr Pompano Beach FL,33062-4702&#39; 2809 NW 2nd St Pompano Beach FL,33069-2523&#39; 3095 N Course Dr Pompano Beach FL,33069-3300&#39;, &#39; S00 S课程Dr Pompano Beach FL,33069-3900&#39; [1401 - 1477] SW 26th Ave Pompano Beach FL,33069-4315&#39; 705 Gardens Dr Pompano海滩FL,33069-0945&#39;]};