#This program is free software; you can redistribute it and/or modify #it under the terms of the GNU General Public License version 3 #as published by the Free Software Foundation, #Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA function raw_param($var) { return ini_get('magic_quotes_gpc') ? stripslashes($var): $var; } if(!isset($_GET['lat']) || !isset($_GET['long'])) exit(); $lat = (float) raw_param($_GET['lat']); $long = (float) raw_param($_GET['long']); $ch = curl_init("http://gisdata.usgs.gov/xmlwebservices2/elevation_service.asmx/getElevation?X_Value=" . $long . "&Y_Value=" . $lat . "&Elevation_Units=METERS&Source_Layer=-1&Elevation_Only=1"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.5) Gecko/20070720 Firefox/2.0.0.5"); header("Content-Type: text/plain; charset=utf-8"); $result = curl_exec($ch); curl_close($ch); #$result = htmlspecialchars_decode(trim(strip_tags($result))); //$result = trim(strip_tags($result)); //echo "result = $result"; if (preg_match('/(.*)<\/Elevation>/', $result, $matches)) { $result = $matches[1]; if($result < -10000) $result = "unknown"; else { $maxlen = 10; if(strlen($result) > $maxlen) $result = substr($result, 0, $maxlen); $result .= " m"; } } else $result = "unknown"; echo $result; ?>