Getting waypoints from leaflet routing machine

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/


Solution 1:

Solution was to not convert to JSON

alert (routeArray[0].latLng.lng);