Question

[Solved] Show multiple markers on Google Maps Using PHP and MySQL

I tried to use PHP and MySQL to show multiple markers on Google Maps. The code below uses PHP to connect to the database so as to get the latitude and longitude.

The problem is the map doesn’t show, but once I delete this line, it works without getting the markers: "var liste_des_points=[<?php echo $listeDesPoints; ?>];". I think the problem is the PHP format.

Please help me with this .

     <%@ 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>
Enquirer: Asma.O

||

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy