$topoUrlMaxCoordinates ) die( 'Too many points to fit into the safe URL length limit.' ); for ( $j = 0; $j < sizeof( $coordinates); $j++ ) { $lat = $coordinates[ $j ][ 0 ]; $lon = $coordinates[ $j ][ 1 ]; if ( $lat < 0.0 ) $lat = 180 + $lat; $lat = $lat / 180.0; $lat = $lat - floor( $lat ); if ( $lon < 0.0 ) $lon = 360 + $lon; $lon = $lon / 360; $lon = $lon - floor( $lon ); for ( $i = 0; $i < 3; $i++ ) { $lat = $lat * $topoUrlCharsLength; $index = floor( $lat ); $lat = $lat - $index; $result = $result . substr( $topoUrlChars, $index, 1 ); $lon = $lon * $topoUrlCharsLength; $index = floor( $lon ); $lon = $lon - $index; $result = $result . substr( $topoUrlChars, $index, 1 ); } $lat = $lat * $topoUrlCharsSqrt; $lon = $lon * $topoUrlCharsSqrt; $index = floor( $lat ) * $topoUrlCharsSqrt + floor( $lon ); $result = $result . substr( $topoUrlChars, $index, 1 ); } return $result; } function topoGetAltitudes( $coordinates ) { global $topoKey; $url = 'http://topocoding.com/api/altitude_v1.php?id=x&key=' . $topoKey . '&l=' . topoEncodeCoordinates( $coordinates ); $content = ''; if ( ini_get( 'allow_url_fopen' ) == '1' ) { $content = file_get_contents( $url ); } else if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 5 ); $content = curl_exec( $ch ); curl_close( $ch ); } else { // see also http://www.php-mysql-tutorial.com/php-tutorial/php-read-remote-file.php die( 'No method to read from remote server was found.' ); } if ($content !== false) { $tmp0 = explode( '[', $content ); if ( $tmp0[ 0 ] == 'topoCall(x,' ) { $tmp1 = explode( ']', $tmp0[ 1 ] ); return explode(',',$tmp1[ 0 ]); } else { die( $content ); } } else { die( 'Unable to resolve altitudes.' ); } } ?>