我正在製作一個Web程序,顯示來自同一個mysql數據庫中的2個表的數據。爲此,我有一個輸出2個json對象(名爲hist和hist2)的php文件。我試圖在Google地圖地圖中將表格中的位置顯示爲標記。我收到錯誤Uncaught SyntaxError: Unexpected end of input
,我會告訴你。獲取未捕獲SyntaxError:意外的輸入結束
<script>
$(document).ready(function() {
var lat = "48.85809";
var lon = "2.294694";
var myPath = [];
var myPath2 = [];
infoWindows = Array();
infoWindows2 = Array();
markers = Array();
markers2 = Array();
var image = 'https://cdn0.iconfinder.com/data/icons/isometric-city-basic-transport/48/truck-front-01-48.png';
var image2 = 'https://i.imgur.com/FGEuaWh.png';
function initMap() {
var myOptions = {
zoom: 16,
center: new google.maps.LatLng(parseFloat(lat),parseFloat(lon)),
panControl: true,
zoomControl: true,
scaleControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map"), myOptions);
}
function addMarker(latLng,time,id, map) {
var marker = new google.maps.Marker({
position: latLng,
map: map,
icon: image,
infoWindowIndex: id
});
var content = '<div id="Marker_Time">' +
'<h6>' + 'Información' + '</h6>' +
'<p>' + time + '</p>' + '</div>';
var infoWindow = new google.maps.InfoWindow({
content: content
});
google.maps.event.addListener(marker, 'click',
function(event) {
infoWindow.open(map, marker);
}
);
infoWindows.push(infoWindow);
markers.push(marker);
return marker;
}
function addMarker2(latLng,time,id,rpm, map) {
var marker2 = new google.maps.Marker({
position: latLng,
map: map,
icon: image,
infoWindowIndex: id
});
var content2 = '<div id="Marker_Time">' +
'<h6>' + 'Información' + '</h6>' +
'<p>' + time2 + '</p>' +'<p>' + rpm +'</p>' + '</div>' ;
var infoWindow2 = new google.maps.InfoWindow({
content: content2
});
google.maps.event.addListener(marker, 'click',
function(event) {
infoWindow.open(map, marker);
}
);
infoWindows2.push(infoWindow2)
markers2.push(marker2);
return marker2;
}
<?php
ob_start();
include_once 'finalquery2.php';
$output = ob_end_clean(); ?>
var json_hist = jQuery.parseJSON(JSON.stringify(hist));
INIT_LAT = parseFloat(json_hist[json_hist.length - 1].Latitude);
INIT_LON = parseFloat(json_hist[json_hist.length - 1].Longitude);
$(json_hist).each(function() {
var ID = this.ID;
var LATITUDE = this.Latitude;
var LONGITUDE = this.Longitude;
var TIME=this.DateTime;
myCoord2 = new google.maps.LatLng(parseFloat(LATITUDE), parseFloat(LONGITUDE));
myPath.push(myCoord2);
var myPathTotal2 = new google.maps.Polyline({
path: myPath,
strokeColor: '#e95d3c',
strokeOpacity: 1.0,
strokeWeight: 5
});
myPathTotal2.setPath(myPath)
myPathTotal2.setMap(map);
addMarker(new google.maps.LatLng(LATITUDE, LONGITUDE),TIME,ID, map);
});
var json_hist2 = jQuery.parseJSON(JSON.stringify(hist2));
INIT_LAT2 = parseFloat(json_hist2[json_hist2.length - 1].Latitude);
INIT_LON2 = parseFloat(json_hist2[json_hist2.length - 1].Longitude);
$(json_hist2).each(function() {
var ID2 = this.ID;
var LATITUDE2 = this.Latitude;
var LONGITUDE2 = this.Longitude;
var TIME2 =this.DateTime;
var rpm = this.RPM;
myCoord2b = new google.maps.LatLng(parseFloat(LATITUDE2), parseFloat(LONGITUDE2));
myPath2.push(myCoord2b);
var myPathTotal2b = new google.maps.Polyline({
path: myPath,
strokeColor: '#000',
strokeOpacity: 1.0,
strokeWeight: 5
});
myPathTotal2b.setPath(myPath)
myPathTotal2b.setMap(map);
addMarker2(new google.maps.LatLng(LATITUDE2, LONGITUDE2),TIME2,ID2,rpm, map);
}); //Here is the Uncaught SyntaxError
</script>
我把它貼在崇高和一切似乎是爲了,所以我不知道爲什麼我得到這個問題,這也阻止了地圖加載在所有。 });
關閉$(json_hist2).each(function() {
一行。
正確縮進代碼對於防止語法錯誤有很長的路要走。這不僅僅是爲了我的強迫症的外觀和滿足。 – nicooga
我知道我知道,但我正在編輯別人的代碼,所以我正在處理這件事,我得到了¯_(ツ)_ /¯我的歉意。這是問題的一部分,還是僅僅是因爲閱讀困難? –
它說有一個未被捕獲的語法錯誤,因爲它期望結束}這就是爲什麼意外的輸入結束,它期望更多 – Hunter