从传单路由机获取航点 [英] Getting waypoints from leaflet routing machine
本文介绍了从传单路由机获取航点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从路线(小叶路线选择机)获取经度和纬度的航路点,以便将其写到数据库中.但是,当我呼叫getwaypoints时,我还会获得有关我不想要的路线的更多数据.
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.
我如何只获取经度/纬度的JSON,以便可以将其写到db中?
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: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <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));
输出
[{"options":{"allowUTurn":false},"latLng":{"lat":-27.38851,"lng":153.11606},"_initHooksCalled":true},{"options":{"allowUTurn":false},"latLng":{"lat":-27.47577,"lng":153.01693},"_initHooksCalled":true}]
请参见小提琴示例: http://jsfiddle.net/drcccx91/8/ >
Please see example fiddle: http://jsfiddle.net/drcccx91/8/
推荐答案
解决方案无法转换为JSON
Solution was to not convert to JSON
alert (routeArray[0].latLng.lng);
这篇关于从传单路由机获取航点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文