4

I'm trying to get the waypoints from a route (leaflet routing machine) as latitude and longitude so I can write these out to a database. However when I call getwaypoints I also get additional data about the route that I don't want.

How do i get just the lat/long as JSON so I can write it out to a db?

    var map = L.map('map').setView([-27.54, 152.9], 10);
    L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all//{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> &copy; <a href="http://cartodb.com/attributions">CartoDB</a>',
    maxZoom: 19
}).addTo(map);

var routeControl = L.Routing.control({waypoints: [
    L.latLng(-27.38851, 153.11606),
    L.latLng(-27.47577, 153.01693)
  ]}).addTo(map);

  var routeArray = new Array();
  routeArray = routeControl.getWaypoints();

  alert (JSON.stringify(routeArray));

Output

[{"options":{"allowUTurn":false},"latLng":{"lat":-27.38851,"lng":153.11606},"_initHooksCalled":true},{"options":{"allowUTurn":false},"latLng":{"lat":-27.47577,"lng":153.01693},"_initHooksCalled":true}]

Please see example fiddle: http://jsfiddle.net/drcccx91/8/

1
  • Will you post here as well? Commented Aug 18, 2015 at 11:38

1 Answer 1

1

Solution was to not convert to JSON

alert (routeArray[0].latLng.lng);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.