-3

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

treyBake
  • 6,440
  • 6
  • 26
  • 57

1 Answers1

-1

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]; ?>'),
Rakesh Jakhar
  • 6,380
  • 2
  • 11
  • 20