/** * Fetch elevation * @param array $latitudes * @param array $longitudes * @return array * @throws \RuntimeException */ protected function fetchElevationFor(array $latitudes, array $longitudes) { $latitudeString = implode(',', $latitudes); $longitudeString = implode(',', $longitudes); $url = 'http://api.geonames.org/srtm3JSON?lats=' . $latitudeString . '&lngs=' . $longitudeString . '&username='******'geonames']) || !is_array($response['geonames'])) { throw new \RuntimeException('Geonames returned malformed code.'); } $elevationData = array(); $responseLength = count($response['geonames']); for ($i = 0; $i < $responseLength; $i++) { $elevationData[] = (int) $response['geonames'][$i]['srtm3']; } return $elevationData; }
/** * Fetch elevation * @param array $latitudes * @param array $longitudes * @return array */ protected function fetchElevationFor(array $latitudes, array $longitudes) { $numberOfCoordinates = count($latitudes); $coordinatesString = ''; for ($i = 0; $i < $numberOfCoordinates; $i++) { $coordinatesString .= $latitudes[$i] . ',' . $longitudes[$i] . '|'; } $url = 'http://maps.googleapis.com/maps/api/elevation/json?locations=' . substr($coordinatesString, 0, -1) . '&sensor=false'; $response = json_decode(\Filesystem::getExternUrlContent($url), true); if (is_null($response) || !is_array($response) || !isset($response['results']) || !isset($response['results'][0]['elevation'])) { throw new \RuntimeException('GoogleMaps returned malformed code.'); } $elevationData = array(); $responseLength = count($response['results']); for ($i = 0; $i < $responseLength; $i++) { $elevationData[] = (int) $response['results'][$i]['elevation']; } return $elevationData; }
/** * Fetch elevation * @param array $latitudes * @param array $longitudes * @return array * @throws \RuntimeException */ protected function fetchElevationFor(array $latitudes, array $longitudes) { $numberOfCoordinates = count($latitudes); $coordinatesArray = array(); for ($i = 0; $i < $numberOfCoordinates; $i++) { $coordinatesArray[] = array($latitudes[$i], $longitudes[$i]); } $coordinatesString = json_encode($coordinatesArray); $url = 'http://www.datasciencetoolkit.org/coordinates2statistics/' . $coordinatesString . '?statistics=elevation'; $response = json_decode(\Filesystem::getExternUrlContent($url), true); if (is_null($response) || !is_array($response) || !isset($response[0]['statistics']) || !isset($response[0]['statistics']['elevation'])) { throw new \RuntimeException('DataScienceToolkit returned malformed code.'); } $elevationData = array(); $responseLength = count($response); for ($i = 0; $i < $responseLength; $i++) { $elevationData[] = (int) $response[$i]['statistics']['elevation']['value']; } return $elevationData; }
/** * Set from url * @param string $url * @param string $cacheKey [optional] if true result will be cached */ public function setFromURL($url, $cacheKey = false) { if ($cacheKey !== false) { $this->Result = Cache::get($cacheKey, 1); if ($this->Result != null) { return; } else { $this->Result = array(); } } if (defined('OPENWEATHERMAP_API_KEY') && strlen(OPENWEATHERMAP_API_KEY)) { $url .= '&APPID=' . OPENWEATHERMAP_API_KEY; } $this->setFromJSON(\Filesystem::getExternUrlContent($url)); if ($cacheKey !== false) { Cache::set($cacheKey, $this->Result, 7200, 1); } }