简体   繁体   中英

Javascript, passing string of addresses to MapQuest API NOT working

I'm dynamically passing a list of addresses, to a string variable and want to plot them on a map using MapQuest API. However when I pass those addresses to my function I'm getting an error.

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 ​ It seems like it's not liking the way I'm passing the String of Addresses.

 '<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>

Is there something I should be doing different here?

dir.route(jsmyRouteStops.trim());

Any help much appreciated, thanks!!!

It worked for me when I removed the quotes around jsmyRouteStops.

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']};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM