我正在尝试使用JSON Feed并使用该信息在Google地图上绘制穿梭巴士。我似乎无法弄清楚如何删除标题。或许我甚至不必这样做,而且我错过了一些东西。 JSON提要如下所示:
{"header":{"gtfs_realtime_version":"1","incrementality":0,"timestamp":1473346401},"entity":[{"id":"1","is_deleted":false,"trip_update":null,"vehicle":{"trip":{"trip_id":"2351087","start_time":"10:30:00","start_date":"20160908","schedule_relationship":0,"route_id":"30"},"position":{"latitude":41.7992477,"longitude":-71.44529,"bearing":360.0,"odometer":0.0,"speed":0.0},"current_stop_sequence":0,"current_status":2,"timestamp":1473346346,"congestion_level":0,"stop_id":"12815","vehicle":{"id":"1604","label":"1604","license_plate":" "}},"alert":null},{"id":"2","is_deleted":false,"trip_update":null,
上面还有大约20个航天飞机。
以下是我对该功能的看法。我得到了#34; Uncaught TypeError:无法读取属性'标题'未定义"。虽然可能会有更多错误,但我无法弄清楚如何摆脱标题。我不是一个程序员,我一直在学习。非常感谢任何帮助。
placeVehicles1();
setInterval(placeVehicles1, 15000);
function placeVehicles1() {
$.getJSON('JSON URL', function(datah){
$.each(datah, function(key){
var hillArray =[key] ;
hillArray[0] =datah['entity']['vehicle'][key]['190'];
hillArray[1] =datah['entity']['vehicle'][key]['191'];
hillArray[2] =datah['entity']['vehicle'][key]['192'];
var number = hillArray[key];
for(h=0; h<101; h++){
{
var Latitudeh = datah['position'][key]['latitude'];
var Longitudeh = datah['position'][key]['logitude'];
var Timeh = datah['entity'][key].timestamp;
var Routeh = datah[key].Route_id;
var Vehicleh = datah[key].Vehicle;
//markersArray.length=0;
markersArray.push(datah);
//Set Lat and Long of each Bus
var imageh = 'GoldBus.png';
var myLatlngh = new google.maps.LatLng(parseFloat(datah['position'][key]['latitude']),parseFloat(datah['position'][key]['logitude']));
if (h=101){
marker=null;
}else{}
var marker = new google.maps.Marker({
position: myLatlngh,
title: 'Shuttle',
map: map,
icon: imageh
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
//}}
// Define Content to Show in popup
var mycontenth = "<div class='infowin'>Time:<h3>" + Timeh + "</h3>" + "Route:<h3>" + Routeh + "</h3>" + "Vehicle:<h3>" + Vehicleh + "</h3></div>";
var infowindowh = new google.maps.InfoWindow({
content: mycontenth
});