我正在创建一个Web程序,它显示同一个mysql数据库中2个表的数据。为此我有一个php文件输出2个json对象(名为hist和hist2)。我试图将表格中的位置显示为Google地图地图中的标记。我在向您展示的行中收到错误Uncaught SyntaxError: Unexpected end of input
。
<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>
我将其粘贴在Sublime中,所有内容都显示正常,所以我不知道为什么我会遇到此问题,这也会阻止地图加载。 });
关闭了$(json_hist2).each(function() {
行。
答案 0 :(得分:0)
在return marker2之后添加一个};我相信你并没有关闭原来的准备功能。