javascript - How to add google Map marker from SQL database -


i have google map , add new marker on each element add on database (with latitude , longitude). have done isn't working. helping.

<?php     $reponse = $bdd->query('select * zdou order id ');     while ($donnees = $reponse->fetch()){      ?>         <p>             <strong>latitude</strong> : <?php echo $donnees['latitude']; ?><br/>             <strong>longitude</strong> : <?php echo $donnees['longitude']; ?><br/>         </p>         <?php             $latitude = $donnees['latitude'];             $longitude = $donnees['longitude'];         ?>         <script>             latitude = <?php echo $latitude ?>;             longitude = <?php echo $longitude ?>;             marker = new google.maps.latlng(latitude, longitude);             var placermarker = new google.maps.marker({position:marker,map:map,title:"zdou"});         </script>         <?php     }     $reponse->closecursor();         ?> 

and have created map user position :

function showposition(position) {             lat = position.coords.latitude;             lon = position.coords.longitude;             latlon = new google.maps.latlng(lat, lon)             mapholder = document.getelementbyid('mapholder')             mapholder.style.height = '250px';             mapholder.style.width = '500px';              var myoptions = {             center:latlon,zoom:12,             maptypeid:google.maps.maptypeid.roadmap,             maptypecontrol:false,             navigationcontroloptions:{style:google.maps.navigationcontrolstyle.small}             }             var map = new google.maps.map(document.getelementbyid("mapholder"), myoptions);             var mypos = new google.maps.marker({position:latlon,map:map,title:"you here!"});          } 

edit : created variable increment each time enter "script" in while loop, , display variable. guess what, variable undefined, script in loop isn't read. still need pls !

try making map variable global. because not defined when creating markers in php loop.

var map; function showposition(position) {     lat = position.coords.latitude;     lon = position.coords.longitude;     latlon = new google.maps.latlng(lat, lon)     mapholder = document.getelementbyid('mapholder')     mapholder.style.height = '250px';     mapholder.style.width = '500px';      var myoptions = {     center:latlon,zoom:12,     maptypeid:google.maps.maptypeid.roadmap,     maptypecontrol:false,     navigationcontroloptions:{style:google.maps.navigationcontrolstyle.small}     }     map = new google.maps.map(document.getelementbyid("mapholder"), myoptions);     var mypos = new google.maps.marker({position:latlon,map:map,title:"you here!"});  } 

look @ https://wrightshq.com/playground/placing-multiple-markers-on-a-google-map-using-api-3/


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -