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

报告相同问题?

悬赏问题

  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)