Jump to content

[SOLVED] Google map API problem


peranha

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.