JS : Unexpected token var avec google map API

Petit nouveau ! | 2 Messages

24 juin 2016, 19:38

Bonjour,
Voila, j'ai un petit soucis.

J'essaie de reprendre des informations de ma DB pour les envoyer sur une google map ainsi que sur un openWindow
J'ai fais le lien php/js grâce à un JSON, lui est fonctionnel.
Mais j'ai une erreur Uncaught SyntaxError: Unexpected token var et je n'arrive pas à trouver ou se trouve le problème.
Si quelqu'un à une idée, ca me sauverait clairement la vie

Code : Tout sélectionner

<?php session_start(); if(isset($_SESSION)) { $id=$_SESSION['ID']; mysql_connect('x.mysql.db', 'x', 'x') or die(mysql_error()); mysql_select_db('x') or die(mysql_error()); $query="SELECT * FROM geoloc JOIN Objet ON geoloc.Owner=Objet.Owner"; $result=mysql_query($query); while($row = mysql_fetch_array($result)){ $results[] = $row; } /** $query="SELECT * FROM geoloc WHERE owner='$id'"; $result=mysql_query($query); $long=mysql_result($result,0,"long"); $lat=mysql_result($result,0,"lat"); $time=mysql_result($result,0,"time"); $query="SELECT * FROM geoloc WHERE owner!='$id'"; $result=mysql_query($query); while($row = mysql_fetch_array($result)){ $results[] = $row; } $query="SELECT * FROM Objet WHERE ID"; $positions = json_encode($results); $name = json_encode($ID); mysql_close(); **/ } else { header("Location:menu.php"); } ?> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0px; padding: 0px } #map_canvas { height: 100% ; width:100%;} </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script> <script type="text/javascript"> function initialize() { var previousPosition = null; var resultats=<?php echo json_encode($results, JSON_PRETTY_PRINT)?>; var map = new google.maps.Map(document.getElementById("map_canvas"), { zoom: 19, center: new google.maps.LatLng(resultats[0]['lat'], resultats[0]['long']), mapTypeId: google.maps.MapTypeId.ROADMAP }); }; if (navigator.geolocation) var watchId = navigator.geolocation.watchPosition(successCallback, null, {enableHighAccuracy:true}); else alert("Votre navigateur ne prend pas en compte la géolocalisation HTML5"); function successCallback(position){ map.panTo(new google.maps.LatLng(position.coords.latitude, position.coords.longitude)); var image = 'logo.png'; var marker = new google.maps.Marker({ position: new google.maps.LatLng(position.coords.latitude, position.coords.longitude), animation: google.maps.Animation.DROP, draggable: false, map: map, icon: image }); //var markers=<?php echo $positions;?>; var image = 'logo.png'; var infoWindows=[]; var markers=[]; for(var i=0; i < resultats.length; i++){ var latitu = resultats[i]['lat']; var longitu = resultats[i]['long']; markers[i] = new google.maps.Marker({ position: new google.maps.LatLng(latitu, longitu), icon: image, animation: google.maps.Animation.DROP, draggable: false, map: map }); infoWindows[i] = new google.maps.InfoWindow({ content: var contentString=resultats[i]['7'] }); // Open the infowindow on marker click google.maps.event.addListener(markers[i], "click", function() { infoWindows[i].open(map, marker[i]); }); } function drop() { for (var i =0; i < markerArray.length; i++) { setTimeout(function() { addMarkerMethod(); }, i * 200); } } if (previousPosition){ var newLineCoordinates = [ new google.maps.LatLng(previousPosition.coords.latitude, previousPosition.coords.longitude), new google.maps.LatLng(position.coords.latitude, position.coords.longitude)]; var newLine = new google.maps.Polyline({ path: newLineCoordinates, strokeColor: "#A4D0AB", strokeOpacity: 1.0, strokeWeight: 2 }); newLine.setMap(map); } previousPosition = position; }; /** // Create the markers ad infowindows. for (index in markers) addMarker(markers[index]); function addMarker(data) { // Create the marker // Create the infowindow with two DIV placeholders // One for a text string, the other for the StreetView panorama. var content = document.createElement("DIV"); title.innerHTML = data.name; content.appendChild(title); var infowindow = new google.maps.InfoWindow({ content: content }); // Open the infowindow on marker click google.maps.event.addListener(marker, "click", function() { infowindow.open(map, marker); }); } **/ </script> </head> <body onload="initialize()"> <div id="map_canvas"></div> </body> </html> </html>
Merci d'avance

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

27 juin 2016, 14:00

salut,

si ce message est indiqué dans la console développeur du navigateur (chrome, firefox etc.) tu devrait avoir la ligne qui cause problème.
Avec chrome tu peux avoir un point d'arrêt dynamique lors qu'il rencontre une erreur (source, au dessus des onglets a droite "pause on exception").

@+
Il en faut peu pour être heureux ......