1

I tried to use PHP and MySQL to show multiple markers on a Google Maps, but it doesn't work as the map doesn't show. Please help me with this and don't forget to change the mapkey. Thank you.

Here is my code:

      <%@ 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());

      //la requête pour obtenir la liste des points
      $result = mysql_query("SELECT latitude,longitude FROM appreciation order by id");

      //récupération de tous les points pour les mettre dans une table façon JavaScript

      $listeDesPoints='';
      while($row = mysql_fetch_array($result)){
      if($listeDesPoints!='') $listeDesPoints.=','; 
      $listeDesPoints.='['.$row['lattitude'].','.$row['longitude'].']';
      }
      //et voilà $listeDesPoints est prêt à être affiché dans le script

      //on ferme la connexion à la base de données
      mysql_close($connexion);
      ?>
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Insert title here</title>
      <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 centreCarte = new google.maps.LatLng(34.02,-6.83);

      var optionsCarte = {
      zoom: 12,
      center: centreCarte,
      keyboardShortcuts: true,
      scrollwheel: true,
      panControl: false,
      mapTypeControl: true,
      overviewMapControl: true,
      rotateControl: true,
      scaleControl: true,
      streetViewControl: true,  
      zoomControl: true,        
      mapTypeId: google.maps.MapTypeId.HYBRID                                        
      }

      var map = new google.maps.Map(document.getElementById("map"), 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: Carte,
      title: "Marqueur-"+i,
           });
      i++;
 }


 }
      </script>
      </head>
      <body onload="initialize()">

      <div id="map" style="width:80%; height:80%" >
      </div>
      </body>
      </html>
BudwiseЯ
  • 1,846
  • 2
  • 16
  • 28
Asma.O
  • 455
  • 2
  • 7
  • 19
  • have you tried more than one browser? I recently built a map using markerclusterer and for some unknown reason my map works great in every browser except chrome! – Joe T Oct 14 '12 at 18:01
  • Can you post a link to your running code, it's hard to debug without seeing it running. – Mano Marks Oct 14 '12 at 18:52

1 Answers1

1

You assign the map object to the variable map, but place the markers on the non existig map "Carte". Try map: map in the Marker object.

torbenc
  • 11
  • 1
  • i change it in the marker object, but the map doesn't show i didn't get what u mean ( a link to ur ronnig code)? – Asma.O Oct 14 '12 at 20:27
  • I think he's talking about the line you have "map: Carte," which should be "map: map," – Mano Marks Oct 14 '12 at 20:37
  • i change it in the marker object, but the map doesn't show i didn't get what u mean ( a link to ur running code)? – Asma.O Oct 14 '12 at 22:27
  • i change it in the marker object, but the map doesn't show i didn't get what u mean ( a link to ur running code)? – Asma.O Oct 15 '12 at 05:02
  • sorry the connection went down yesterday, that's why i didn't respond – Asma.O Oct 15 '12 at 05:05
  • thank u AbidHussain but what i want is to get my latitude and logitude from mySQL table. @ManoMarks i tried with V3 but the problem persist, i tried so many tuto about this ( for example: http://tips4php.net/2010/10/use-php-mysql-and-google-map-api-v3-for-displaying-data-on-map/) the map shows but not the markers. – Asma.O Oct 15 '12 at 19:20
  • Please post a link to your code live. Your comments are getting very confusing. I know it's frustrating but we can't help you if you're just saying "it's not working". There's nothing wrong with the tutorials so there must be something wrong with the code. In your code you put "map: Carte" instead of "map: map" which looks like the problem to me but unless we look at the code we can't figure out what's wrong. – Mano Marks Oct 16 '12 at 19:01
  • ok sorry am confused, i posted a new questions (sorry i didn't see your answer until i post another question) here's the link: http://stackoverflow.com/questions/12957225/show-multiple-markers-on-google-maps-using-php-and-mysql – Asma.O Oct 18 '12 at 14:40