Missing something

7 posts / 0 new
Last post
Missing something

Hi and sorry if I am wasting time on things that have already been asked but I am extremely new at this.  I can get data from the api's but I can't get a map to display.  I have seen the examples and the leaf tutorial on creating a map but it does not say how to create the map and center it where I would like it to be without hardcoding in the latLngs.

My scenario will be rather simplistic as opposed to some of the stuff I have been reading in these posts.  I have 6 sites  [  6 different lat,Lgs ] and my page with a map will be displayed after a site is selcted  centered on the associated lat/lng for the site I picked.  In addition to that each site has multiple deliveries associated which I would like to display with the route drawn on the map as well.  My application is a local one and only available on our network.

I haven't seen anything on here I can get going with so any help would be greatly appreciated.  I have a key but don't know if it is the proper key for something like this.

I have tried https://www.mapquest.com/directions and can get the different points to display and the route to display but it won't zoom properly or center where i want it to which would cause the users of my app to have to center, zoom, zoom, zoom recenter etc.

Thanks in advance






If I understand correctly you

If I understand correctly you want to create a map with a specific center and zoom level depending on a variable for at least the center. Then after the map is created add a route with locations nearby that center. This code started as a route that was included on map creation but the center and zoom can easily be replaced by some other variable latLng array and/or zoom integer. The original values I used that came from the route are commented out so you can still use them if needed or discard if not.




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

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

<script type="text/javascript">

var L;


window.onload = function() {

"use strict";

var map, directions;

L.mapquest.key = "KEY";

directions = L.mapquest.directions();


start: "Denver, CO",

end: "Golden, CO",

options: {doReverseGeocode:false}



// directions.route callback function

function(err, data) {

var bounds, c, z;

if (err.message) {


} else {


// get route bounds to set center and zoom

bounds = data.route.boundingBox;

c = [39.750523,-104.999734], //L.mapquest.util.getCenterFromBoundingBox(bounds),

z = 8, //L.mapquest.util.getZoomFromBoundingBox(bounds),


// let's make a map given the bounds

map = L.mapquest.map("map", {

center: c,

zoom: z,

layers: L.mapquest.tileLayer("map")



// add route ribbon


directionsResponse: data,

fitBounds: false








<body style="border: 0; margin: 0;">

<div id="map" style="width: 800px; height: 530px;"></div>



very close to what I am trying to do

Thank you for responding so quickly.  I saw this code on one of the posted pages but could not figure out how to use it until now.  :)

My starting point and map center would be the same.


start: "<selected Site>, end: "<last associated stop in list>", and include <stop1 address>, <stop2 address>...<next to last stop in list address> in route.  shown with stop number indicaters [ markers ].

I am supposed to demo this capability the week of the 3rd [ new year ] and I did not have a clue how to do any of this.  Is there some documentation that helps with this for absolute beginners?  The tutorials I saw assume a level of experience with the mapping world way above mine it seems or it could be that I am just thick as a brick.  :)

I am grateful for what ever assitance you can provide.





I think I saw the answer

Could waypoints be the way to accomplish what I am trying to do?

Hi Mike,

Hi Mike,


Yes, waypoints would be those points between the route origin and destination. You can have up to 25 total locations in your route.

Thank You

Thanks for your help.  I appreciate it

You're welcome. I'm glad it
You're welcome. I'm glad it helped.