Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle maps markers with javascript and PHP
    primarykey
    data
    text
    <p>I am building an application that has a database of people's names, info about them and their current location. I managed to create a maps using Google maps javascript API, and mark your current location. however, i cant seem to be able to use a PHP loop to place a marker with an info window for every person in my database. Here is my code:</p> <pre><code> lat = position.coords.latitude; lon = position.coords.longitude; //init map myOptions = { center: new google.maps.LatLng(lat, lon), zoom: 15, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var image = 'http://i43.tinypic.com/v48d1w.png'; var loca = new google.maps.LatLng(lat, lon); var currnetLocationMarker = new google.maps.Marker({ position: loca, map: map, animation: google.maps.Animation.DROP, icon: image }); var contentString; var marklatlng; &lt;?php require("connect.php"); $query = mysql_query("SELECT * FROM gigs"); $i = 0; while($data = mysql_fetch_array($query)) { echo " contentString = 'Name: &lt;b&gt;" . $data['name'] . "&lt;/b&gt;&lt;br&gt; Info: &lt;b&gt;" . $data['desc'] . " &lt;/b&gt;'; var infowindow" . $i . " = new google.maps.InfoWindow({ content: contentString }); marklatlng = new google.maps.LatLng(" . $data['lat'] . ", " . $data['lng'] . "); var marker" . $i . " = new google.maps.Marker({ position: markLatlng, map: map, }); google.maps.event.addListener(marker" . $i . ", 'click', function() { infowindow" . $i . ".open(map,marker" . $i . "); }); "; $i++; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload