Ago 16

Description

This package offers a function called mysqlAKML (resource $mysqlResult, string $documentName=’kml’, string $itemName=’Placemark’); used to output a Mysql result with the following fields:

name: TEXTVALUE – The Name of the marker
description: TEXTVALUE – The description shown in the info window when marker clicked
coordinates: TEXTVALUE as (DOUBLE + ‘, ‘ + DOUBLE) like “longitude, latitude”

Usage

So an easy way to obtain the KML would be:

$qString = "SELECT
markerName AS name,
myText AS description,
CONCAT (latitude, ', ', longitude) AS coordinates
FROM myTable";
 
$result = mysql_query($qString);
$myKML = mysql_KML($result);

A complete example:

File getPoints.php

<?
require ('connetion.php');
require ('mysqlAKML-1.1.php');
 
// obtain the MySQL resutl
$makers = mysql_query($queryString);
 
// KML Content-Type (application/vnd.google-earth.kml+xml)
header ("Content-type: application/vnd.google-earth.kml+xml");
header('Content-Disposition: attachment; filename="markers.kml"');
// Display the file content
echo mysql_KML($markers);
 
mysql_close();
?>

Then, if we want to load this KML in a Google Map with the Google Maps API with JavaScript, we shoul add the following code to our load() function:

// JavaScript
function load() {
...
...
// add Markers fetched from the DB to the map
var geoXml = new GGeoXml(PATH_TO_FILE + 'getPoints.php');
map.addOverlay(geoXml);
...
...
}

Thats all! Feel free to modify the file but remember to leave my name! See the working example in the link below

Working Example

Example

Downloads

Download Package File (mysqlAKML-1.1.php)

Usefull Links

GGeoXML in Google Maps API Reference

Leave a Reply

Powered By Wordpress - Theme Provided By Wordpress Theme - No Credit Auto Loan