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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.