So, the code to create the map:
<?php
// 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;
if(empty($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 ($im, 255,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
imagefilledrectangle($im,$pt["x"]-2,$pt["y"]-2,$pt["x"]+2,$pt["y"]+2,$red);
// 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");
imagepng($im);
imagedestroy($im);
?>
To load the map call the PHP code from an IMG tag, passing the longitude and
latitude in the long and lat variables:
latitude in the long and lat variables:
<img src=”map_code.php?long=long&lat=lat“>
You could easily modify this code to read long/lat coordinates from a database
or a delimited text file and plot multiple points.
or a delimited text file and plot multiple points.
Summary
This is a very basic script. However the basic principle will allow you to draw
very complicated maps.
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!