#native_company# #native_desc#
#native_cta#

GIS Mapping with PHP Page 3

By Simon Moss
on October 23, 2003

Plots and Schemes

The basic steps for generating the map are:
  • Load the background map.
  • Convert and scale the long/lat coordinates to screen coordinates.
  • Plot the point.
  • Return the finished map as an image.
To convert the long/lat to screen coordinate we have a created a function called
getlocationcoords. This takes the longitude and latitude coordinates
plus the size of the base map and return the screen coordinates in an associative
array. $width and $height are calculated from the
size of the background image. In future projects these variables are used scale
the map and set the zoom level.

<?php

function getlocationcoords($lat$lon$width$height)

{  

    
$x = (($lon 180) * ($width 360));

    
$y = ((($lat * -1) + 90) * ($height 180));

    return array(
"x"=>round($x),"y"=>round($y));

}

?>



Once the coordinates have been converted it’s as simple as drawing a rectangle
on the base map using the returned array to mark our location.