Я попытался использовать PHP и MySQL для отображения нескольких маркеров на Картах Google. В приведенном ниже коде используется PHP для подключения к базе данных, чтобы получить широту и долготу.
Проблема заключается в том, что карта не отображается, но как только я удалю эту строку, она работает без получения маркеров: "var liste_des_points=[<?php echo $listeDesPoints; ?>];"
, Я думаю, что проблема в формате PHP.
Пожалуйста, помогите мне с этим .
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <?php $connexion=mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("survey",$connexion) or die(mysql_error()); $result = mysql_query("SELECT latitude, longitude FROM appreciation order by id"); $listeDesPoints=''; while($row = mysql_fetch_array($result)){ if($listeDesPoints!='') $listeDesPoints.=','; $listeDesPoints.='['.$row['latitude'].','.$row['longitude'].']'; } mysql_close($connexion); ?> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } </style> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyB3is760vHXhki9vS_LpiWAig8a33GP3CY&sensor=false"> </script> <script type="text/javascript"> function initialize() { var optionsCarte = { center: new google.maps.LatLng(34.02,-6.83), zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), optionsCarte); var liste_des_points=[<?php echo $listeDesPoints; ? >]; var i=0,li=liste_des_points.length; while(i<li){ new google.maps.Marker({ position: new google.maps.LatLng(liste_des_points[i][0], liste_des_points[i][1]), map: map, }); i++; } } </script> </head> <body onload="initialize()"> <div id="map_canvas" style="width:100%; height:100%"> </div> </body> </html>
.<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <?php $connexion=mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("survey",$connexion) or die(mysql_error()); $result = mysql_query("SELECT latitude, longitude FROM appreciation order by id"); $listeDesPoints=''; while($row = mysql_fetch_array($result)){ if($listeDesPoints!='') $listeDesPoints.=','; $listeDesPoints.='['.$row['latitude'].','.$row['longitude'].']'; } mysql_close($connexion); ?> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } </style> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyB3is760vHXhki9vS_LpiWAig8a33GP3CY&sensor=false"> </script> <script type="text/javascript"> function initialize() { var optionsCarte = { center: new google.maps.LatLng(34.02,-6.83), zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), optionsCarte); var liste_des_points=[<?php echo $listeDesPoints; ? >]; var i=0,li=liste_des_points.length; while(i<li){ new google.maps.Marker({ position: new google.maps.LatLng(liste_des_points[i][0], liste_des_points[i][1]), map: map, }); i++; } } </script> </head> <body onload="initialize()"> <div id="map_canvas" style="width:100%; height:100%"> </div> </body> </html>
в<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <?php $connexion=mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("survey",$connexion) or die(mysql_error()); $result = mysql_query("SELECT latitude, longitude FROM appreciation order by id"); $listeDesPoints=''; while($row = mysql_fetch_array($result)){ if($listeDesPoints!='') $listeDesPoints.=','; $listeDesPoints.='['.$row['latitude'].','.$row['longitude'].']'; } mysql_close($connexion); ?> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } </style> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyB3is760vHXhki9vS_LpiWAig8a33GP3CY&sensor=false"> </script> <script type="text/javascript"> function initialize() { var optionsCarte = { center: new google.maps.LatLng(34.02,-6.83), zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), optionsCarte); var liste_des_points=[<?php echo $listeDesPoints; ? >]; var i=0,li=liste_des_points.length; while(i<li){ new google.maps.Marker({ position: new google.maps.LatLng(liste_des_points[i][0], liste_des_points[i][1]), map: map, }); i++; } } </script> </head> <body onload="initialize()"> <div id="map_canvas" style="width:100%; height:100%"> </div> </body> </html>