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> Link to comment https://forums.phpfreaks.com/topic/138653-solved-google-map-api-problem/ 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> Link to comment https://forums.phpfreaks.com/topic/138653-solved-google-map-api-problem/#findComment-724965 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. Link to comment https://forums.phpfreaks.com/topic/138653-solved-google-map-api-problem/#findComment-725016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.