peranha Posted December 28, 2008 Share Posted December 28, 2008 I have this code and I cannot get the points to display on the map. It keeps saying marker is not defined. Line 53 <script type="text/javascript"> function createMarker(point,html) { var marker = new GMarker(point); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); return marker; } window.onload = showMap; function showMap() { var map = new GMap(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.centerAndZoom(new GPoint(-108.5010, 45.7982), 14); <?php if (mysql_num_rows($cityresult) > 0) { // yes // print them one after another while($row = mysql_fetch_row($cityresult)) { ?> var point = new GLatLng(<?php echo $row[1]; ?>, <?php echo $row[0]; ?>); createMarker(point, '<?php echo $row[2]; ?>'); map.addOverlay(marker); <?php // Line 53 ?> <?php } } ?> } </script> Quote Link to comment Share on other sites More sharing options...
corbin Posted December 28, 2008 Share Posted December 28, 2008 createMarker(point, '<?php echo $row[2]; ?>'); You never assign that to a variable. I'm not familiar with the Google Maps API, but based on your code, this should work: <script type="text/javascript"> function createMarker(point,html) { var marker = new GMarker(point); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); return marker; } window.onload = showMap; function showMap() { var marker; var map = new GMap(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.centerAndZoom(new GPoint(-108.5010, 45.7982), 14); <?php if (mysql_num_rows($cityresult) > 0) { // yes // print them one after another while($row = mysql_fetch_row($cityresult)) { ?> var point = new GLatLng(<?php echo $row[1]; ?>, <?php echo $row[0]; ?>); marker = createMarker(point, '<?php echo $row[2]; ?>'); map.addOverlay(marker); <?php // Line 53 ?> <?php } } ?> } </script> Quote Link to comment Share on other sites More sharing options...
peranha Posted December 28, 2008 Author Share Posted December 28, 2008 Thanks, that worked. The tutorial that I followed didn't have that in it for some reason. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.