google maps

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

google maps

Post by garry27 »

i'm at my wits end with this now so i'm going to show you the entire two scripts in my web appliation to see if you can figure out why it won't work.

the first script is map_data.php which pulls out coordinates out of a database and formats them in a way js should understand. you can see an example of the output data at http://www.nl-webspace.co.uk/~unn_p9218 ... p_data.php

Code: Select all

<?php
//function getPubMarkers() {
    require_once('common.php');
    db_connect();
    $sql = mysql_query ( " select Latitude, Longitude, pubName, pubStreetNo, pubStreet, pubCity, pubCounty, 
                         pubPostcode, pubPhone from Pubs " ) or die( 'Invalid query: ' . mysql_error() ); 
	$markers = array();
    while( $elements = mysql_fetch_array($sql) ) { 
	 $br = '<br>';       
     $markers[] =      '{'   
	                         ." 'latitude' : " .$elements[0] .','
							 ." 'longitude' : " .$elements[1] .','
	                         ." 'name' : '" .$elements[2] ."' "
	                         //."'address': '" .$elements[3] .$br .$elements[4] .$br .$elements[5]   
	                         //                .$br .$elements[6] .$br .$elements[7] ."' ,"
	                        // ."'phone': '" .$elements[8] ."'"
				      .'},';
    }
     //convert array into a single string variable  
     $markers  = implode( ' ', $markers );
     //remove the end comma in the string				
     $markers = substr_replace($markers,"",-1);				
     
	 
	 $jscript = 'var markers =' .'[' .$markers .'];';  
	// return $jscript; 
     
//}
print $jscript;
?>

the second script is map_function.js which i copied directly from a book:

Code: Select all

var centerLatitude = 54.52473;        // global var	
var centerLongitude = -1.556582;         // global var
var startZoom = 13;
var map;
 
//function addMarker()
function init() 
{								// JavaScript coding from Purvis et al (2006: p.22, p.29)

  if ( GBrowserIsCompatible() ) {                      										
    map = new GMap2(document.getElementById("mapviewer"));
    map.addControl( new GSmallMapControl () );
    //map.addControl( new GMap2TypeControl () );           //undefined?
    //map.addControl( new GLatLng ( centerLatitude, centreLongitude ), startZoom );
	//location = GLatLng(centerLatitude, centerLongitude);
	
	map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
    for (id in markers) {
	addMarker(markers[id].latitude, markers[id].longitude, markers[id].name);   // line 19
    } 
  }
}

 //opens map when browser window loads up
window.onload = init;
window.onunload = GUnload;
the script addresses are referenced on the page header of my webpage in the order described. when i load the webpage i get a google map set at the speciified coordinates and zoom level but no markers. my debugger points to line 19 of map_functions.js and states 'error: object expected'

please somone tell me what i can do to fix this
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

It looks like "markers" is the object it is referring to. Are you sure that map_data.php's output is accessible to map_function.js?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Do you have a function named addMaker? Gmaps expects a GlatLng object for the marker's coordinates...
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

Post by garry27 »

aaronhall, this is the source code on my html header:

<SCRIPT language=JavaScript src= ' http://maps.google.com/maps?file=api&v= ... xxxxxxxxxx' ></SCRIPT> <SCRIPT language=JavaScript src= ' map_data.php ' ></SCRIPT> <SCRIPT language=JavaScript src= ' map_fs.js ' ></SCRIPT><meta http-equiv='Content-Type'
content='text/html;
charset=utf-8' />
<title>Create Pub Crawl</title>
</head>

nickvd wrote:Do you have a function named addMaker? Gmaps expects a GlatLng object for the marker's coordinates...
all i have is:

Code: Select all

for (id in markers) { 
        addMarker(markers[id].latitude, markers[id].longitude, markers[id].name);   // line 19
written in the init function i've described. its these two lines that my debuggers having problems with.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

altyfc
Forum Newbie
Posts: 1
Joined: Wed Nov 08, 2006 4:02 am

Post by altyfc »

Alternatively, if you're still getting nowhere, you might like to look at our new site at http://www.aardvarkmap.net as an alternative solution.

Good luck!
Post Reply