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>
2
  • 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! Commented Oct 14, 2012 at 18:01
  • Can you post a link to your running code, it's hard to debug without seeing it running. Commented Oct 14, 2012 at 18:52

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

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)?
I think he's talking about the line you have "map: Carte," which should be "map: map,"
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)?
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)?
sorry the connection went down yesterday, that's why i didn't respond
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.