1

在此处输入图像描述

这是我的代码。

function saveTrip()
{
routeData.clear();
for (var i = 0; i < dirDisplay.directions.routes[0].legs.length; i++) {
for (var j = 0; j < dirDisplay.directions.routes[0].legs[i].steps.length; j++) {
routeData.push(dirDisplay.directions.routes[0].legs[i].steps[j].path);
}
}
routeLinesRef.push(routeData, function(error){
if (error) {
$('#savedSpan').html('Data could not be saved.' + error);
} else {
$('#savedSpan').html('Data saved successfully!');
}
});
}

Array.prototype.clear = function() {
this.splice(0, this.length);
};

routeLinesRef.limit(10).on('child_added', function(snapshot)
{
// loop over each route we get from firebase
route = snapshot.val();

如图所示,应该编写什么函数来写入层次结构?

id = snapshot.name();
// make an array that is initially blank
// It will contain all the latitude and longitudes of each point on in the route
var routeCoordinates = [];
// This loops over each point on the route
for (var i=0; i<route.length; i++)
{

for (var j in route[i])
{
if (j==0 && i>0)
{
continue
}
else
{

这部分只是获取路线上的每个点,并将其转换为 google maps LatLng 对象。例如,如果数据是 [58.23, 18.8],它将对其执行:new google.maps.LatLng(58.23, 18.8) ,这会将其转换为 google maps 喜欢的格式。

if (route[i][j].lb && route[i][j].mb) {
routeCoordinates.push(new google.maps.LatLng
(route[i][j].lb, route[i][j].mb));
//console.log(j + ' ' + snapshot.val()[route][i][j].lb, snapshot.val()[route][i][j].mb);
}
}
}
}

我应该怎么办?我找不到任何教程或任何东西。

4

0 回答 0