【发布时间】:2019-08-29 11:08:26
【问题描述】:
我有一些代码可以使用 LAT&LONG,数据保存在 txt 中,并将其显示为 html 中的 Google 地图。但是导入txt的php函数根本不起作用。知道问题出在哪里吗?
我尝试在其他机器上运行,系统中,rasp是挂载在Nginx中的
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>LOCATION</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?key="></script>
<?php $array = explode("\n", file_get_contents('locations.txt')); ?>
<script>
function initialize() {
var mapOptions = {
zoom: 20,
center: new google.maps.LatLng(<?php echo $array[0]; ?>),
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var flightPlanCoordinates = [
<?php foreach ($array as $arrayItem) {
echo 'new google.maps.LatLng('.$arrayItem.'),';
} ?>
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
Trows 错误“SyntaxError: Unexpected token '
【问题讨论】:
标签: php html google-maps-api-3