lundi 27 septembre 2010

Google Maps PHP and your own dataBase

The last post found a PHP lib which functioned well.
Then it is relatively easy to insert the PHP needed to get the stored data from your dataBase:

Just insert: (in the file of the last post)

$database="DATABASENAME";
$db=mysql_connect("localhost", "YOURUSERNAME", "YOURPASSWORD");
@mysql_select_db($database) or die( "Unable to select database...");

$mydBaseCounter = 0;
$q
="SELECT *
FROM `POI_Table`
ORDER BY id ASC
";
$page_imp_r=mysql_query($q) or print(mysql_error());

while ($page_imp=mysql_fetch_array($page_imp_r)){
$loop_marker = $MAP_OBJECT->addMarkerByCoords( $page_imp['lon'],$page_imp['lat'],'contrechoc.com '.$mydBaseCounter.' ',' ');
//to check the coordinates from the dBase
echo $mydBaseCounter." ".$page_imp['lat']." ".$page_imp['lon']."
";
$mydBaseCounter++;
}

testing: http://www.contrechoc.com/layar/secondGooggleMapPHPTest2.php

download source file phpTest2

The last obstacle was the order of latitude, longitude, some defenition start with latitude, others with longitude, so check this, otherwise you end up in Somalia instead of Hollland....

The one but last obstacle is connecting to your database, somehow, this always poses me problems :-), where to put the database name, where the user etc.....

The funny thing is, that the PHP generates a JAVASCRIPT file (!). This can be seen opening the source in the browser.

Aucun commentaire:

Enregistrer un commentaire