Ok,
try something like this:
<?php
function getPictureCoordinates($value,$lanlonstart,$lanlonend,$scale) {
/*
yt-value = a;
value-yb = b;
div = a/b
pic:
-value = a
value-yb = b;
-value/(value-yb) = (a/b)
-value = (a/b)*(value-yb);
-value = (a/b)*value-((a/b)*yb);
(a/b)*yb = ((a/b)+1)*value;
value = (a/b)*yb
--------
(a/b)+1
*/
$a = $lanlonstart-$value;
$b = $value-$lanlonend;
$div = $a/$b;
$platlon = ($div*$scale)/($div+1);
return $platlon;
}
function getlocationcoords($lat, $lon, $width, $height,$lattop,$latbottom,$lonleft,$lonright)
{
$x = getPictureCoordinates($lon,$lonleft,$lonright,$width);
//$x = (($lon + 180) * ($width / 360));
$y = getPictureCoordinates($lat,$lattop,$latbottom,$height);
return array("x"=>round($x),"y"=>round($y));
}
// 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.
$lattop = 30.543;
$latbottom = -2.54343243;
$lonleft = -95.32332;
$lonright= +120.4322;
if(empty($long))$long = -80;
if(empty($lat)) $lat = 10;
// 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 = imagecreatefrompng("usmap.png");
$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,$lattop,$latbottom,$lonleft,$lonright);
// 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);
?>
You need to get the left most and right most longitude and the top most and bottom most latidude of your map. Set them in the PHP script:
$lattop = 30.543;
$latbottom = -2.54343243;
$lonleft = -95.32332;
$lonright= +120.4322;
These are no real world values, just a test.
It seemed to work on my server. I hope I didn't mix up longitude and latidude 😉
Thomas