dotxxh0998 2019-04-08 10:15
浏览 760
已采纳

如何修复“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>
<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("
", 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 error "SyntaxError: Unexpected token '<'" In the line 20. Specifically in the php function to add the array of the txt.

</div>
  • 写回答

1条回答 默认 最新

  • 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]; ?>'),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型