#native_company# #native_desc#

GIS Mapping with PHP Page 4

By Simon Moss
on October 23, 2003

So, the code to create the map:


// These are the coordinates the location we wish to plot.<br>

// These are being passed in the URL, but we will set them to a 

// default if nothing is passed.

if(empty($long))$long = -63.10774861954596;

$lat)) $lat 46.2899306519141;

// First we load the background/base map. We assume it's located in same dir 

// as the script.

// This can be any format but we are using JPG in this example

// We will also allocate the color for the marker 

$im imagecreatefromjpeg("earth_310.jpg");

$red imagecolorallocate ($im255,0,0);

// Next need to find the base image size.

// We need these variables to be able scale the long/lat coordinates.

$scale_x imagesx($im);

$scale_y imagesy($im); 

// Now we convert the long/lat coordinates into screen coordinates

$pt getlocationcoords($lat$long$scale_x$scale_y);

// Now mark the point on the map using a red 4 pixel rectangle


// Return the map image. We are using a PNG format as it gives better final 

image quality than a JPG

header ("Content-type: image/png");




To load the map call the PHP code from an IMG tag, passing the longitude and
latitude in the long and lat variables:

<img src=”map_code.php?long=long&lat=lat“>


map of world with coordinate mapped out


You could easily modify this code to read long/lat coordinates from a database
or a delimited text file and plot multiple points.


This is a very basic script. However the basic principle will allow you to draw
very complicated maps.

The important part is the getlocationcoords
function – once you have geocoded your data and have the routines to plot the
points on the screen, the sky’s the limit!