2019-04-08 10:15 阅读 505

如何修复“SyntaxError:Unexpected token'<'”[复制]

Well I have some code to use LAT&LONG, data saved in a txt, and display it as a Google Map in html. but the php function to import the txt, no works at all. Any idea of what the problem is ?

I tried to run in other machines, and system, in the rasp is mounted in Nginx

<!DOCTYPE html>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
    <script src=""></script>
    <?php $array = explode("
", file_get_contents('locations.txt')); ?>
    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
    google.maps.event.addDomListener(window, 'load', initialize);
        <div id="map-canvas"></div>

Trows error "SyntaxError: Unexpected token '<'" In the line 20. Specifically in the php function to add the array of the txt.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douduan1953 douduan1953 2019-04-08 10:16

    On Line 20 , you have

    center: new google.maps.LatLng(<?php echo $array[0]; ?>),

    Replace it with

    center: new google.maps.LatLng('<?php echo $array[0]; ?>'),
    点赞 评论 复制链接分享