public function getPoints($tripId, $timezone) { $url = "/trips/{$tripId}.json"; $page = $this->api->get($url); $this->output('.'); if (!$page) { $this->error .= $this->api->getError(); return null; } $json = json_decode($page); if (!$json) { $this->error .= "RWGps didn't return JSON for {$url}, " . $page; return null; } $track_points = $json->trip->track_points; if (!$track_points || sizeof($track_points) == 0) { $this->error .= "RWGps didn't return any points"; return null; } date_default_timezone_set($timezone); $start_day = isset($track_points[0]->t) && is_int($track_points[0]->t) ? date("Y-m-d", $track_points[0]->t) : null; $points = new Points($start_day, $this->echoCallback, $this->googleMaps, $timezone); foreach ($track_points as $track_point) { if (!isset($track_point->y) || !isset($track_point->x)) { continue; } $lat = $track_point->y; $long = $track_point->x; $time = null; if (isset($track_point->t)) { $time = $track_point->t; } $points->add($lat, $long, $time); $this->rareDot(); } return $points; }
public function getPoints($start_date, $tz) { global $scratchDirectory; $gpx_file = $scratchDirectory . DIRECTORY_SEPARATOR . $this->getUserId() . "-" . preg_replace("/:/", "_", $start_date) . "." . self::GPX_SUFFIX; if (!file_exists($gpx_file)) { return null; } $xml = file_get_contents($gpx_file); preg_match_all('/<trkpt[^>]*>.*?<\\/trkpt>/s', $xml, $trkpts); $points = new Points($start_date, $this->echoCallback, null, $tz); foreach ($trkpts[0] as $trkpt) { preg_match('/<trkpt.*lat="([^"]*)"/', $trkpt, $matches); $lat = $matches[1]; preg_match('/<trkpt.*lon="([^"]*)"/', $trkpt, $matches); $lon = $matches[1]; preg_match('/<time>([^<]*)<\\/time>/', $trkpt, $matches); $time = $matches[1]; $points->add($lat, $lon, $time); $this->rareDot(); } return $points; }
public function getPoints($workoutId, $tz = null) { $url = "api/workout/get"; $params = ['fields' => 'points,simple', 'workoutId' => $workoutId]; for ($i = 0; $i < self::RETRIES; $i++) { $page = $this->getPageWithDot($url, $params); $json_decode = json_decode($page); if ($json_decode) { break; } } if (!$json_decode) { // three tries, and we can't get points $this->error .= "{$page}<br>"; return null; } $points = new Points($json_decode->start_time, $this->echoCallback, $this->googleMaps); $points->setGenerateGPX(true); if (isset($json_decode->points) && is_array($json_decode->points)) { foreach ($json_decode->points as $point) { if (isset($point->lat) && isset($point->lng) && isset($point->time)) { $points->add($point->lat, $point->lng, $point->time); } } } return $points; }
public function testGpx() { $points = new Points("2015-12-27 21:56:00 UTC", array($this, 'myEcho')); $points->clearStoredPoint(); $points->setGenerateGPX(true); $points->add(51.438407, -0.331903, "2015-12-28T10:40:13Z"); $points->add(51.438235, -0.331777, "2015-12-28T10:40:16Z"); $points->add(51.437872, -0.33151, "2015-12-28T10:40:22Z"); $points->add(51.437686, -0.331372, "2015-12-28T10:40:25Z"); $points->add(51.437498, -0.331266, "2015-12-28T10:40:28Z"); $points->add(51.437145, -0.331079, "2015-12-28T10:40:34Z"); $this->assertEquals(include 'data/expected/gpx.php', $points->gpx()); }