[], // 'units' => 'metric', // 'pace' => false ]; $pFFA = new adriangibbons\phpFITFileAnalysis(__DIR__ . $file, $options); } catch (Exception $e) { echo 'caught exception: '.$e->getMessage(); die(); } // Google Static Maps API $position_lat = $pFFA->data_mesgs['record']['position_lat']; $position_long = $pFFA->data_mesgs['record']['position_long']; $lat_long_combined = []; foreach ($position_lat as $key => $value) { // Assumes every lat has a corresponding long $lat_long_combined[] = [$position_lat[$key],$position_long[$key]]; } $delta = 0.0001; do { $RDP_LatLng_coord = simplify_RDP($lat_long_combined, $delta); // Simplify the array of coordinates using the Ramer-Douglas-Peucker algorithm. $delta += 0.0001; // Rough accuracy somewhere between 4m and 12m depending where in the World coordinates are, source http://en.wikipedia.org/wiki/Decimal_degrees $polylineEncoder = new PolylineEncoder(); // Create an encoded string to pass as the path variable for the Google Static Maps API foreach ($RDP_LatLng_coord as $RDP) { $polylineEncoder->addPoint($RDP[0], $RDP[1]); } $map_encoded_polyline = $polylineEncoder->encodedString(); $map_string = '&path=color:red%7Cenc:'.$map_encoded_polyline; } while (strlen($map_string) > 1800); // Google Map web service URL limit is 2048 characters. 1800 is arbitrary attempt to stay under 2048 $LatLng_start = implode(',', $lat_long_combined[0]); $LatLng_finish = implode(',', $lat_long_combined[count($lat_long_combined)-1]); $map_string .= '&markers=color:red%7Clabel:F%7C'.$LatLng_finish.'&markers=color:green%7Clabel:S%7C'.$LatLng_start; // Google Time Zone API $date = new DateTime('now', new DateTimeZone('UTC')); $date_s = $pFFA->data_mesgs['session']['start_time']; $url_tz = 'https://maps.googleapis.com/maps/api/timezone/json?location='.$LatLng_start.'×tamp='.$date_s.'&key=AIzaSyDlPWKTvmHsZ-X6PGsBPAvo0nm1-WdwuYE'; $result = file_get_contents($url_tz); $json_tz = json_decode($result); if ($json_tz->status == 'OK') { $date_s = $date_s + $json_tz->rawOffset + $json_tz->dstOffset; } else { $json_tz->timeZoneName = 'Error'; } $date->setTimestamp($date_s); // Google Geocoding API $location = 'Error'; $url_coord = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='.$LatLng_start.'&key=AIzaSyDlPWKTvmHsZ-X6PGsBPAvo0nm1-WdwuYE'; $result = file_get_contents($url_coord); $json_coord = json_decode($result); if ($json_coord->status == 'OK') { foreach ($json_coord->results[0]->address_components as $addressPart) { if ((in_array('locality', $addressPart->types)) && (in_array('political', $addressPart->types))) { $city = $addressPart->long_name; } elseif ((in_array('administrative_area_level_1', $addressPart->types)) && (in_array('political', $addressPart->types))) { $state = $addressPart->short_name; } elseif ((in_array('country', $addressPart->types)) && (in_array('political', $addressPart->types))) { $country = $addressPart->long_name; } } $location = $city.', '.$state.', '.$country; } ?>
This is a demonstration of the phpFITFileAnalysis class available on GitHub