Created
November 26, 2015 01:39
-
-
Save shakhal/0db7619a668e17e62ed1 to your computer and use it in GitHub Desktop.
Extracting Your Own Location Information From Google
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Today's time is needed to get the bounding for the request | |
$currentTime = time(); | |
// Beginning and end of the day | |
$startTime = strtotime("midnight", $currentTime); | |
$endTime = strtotime("tomorrow", $startTime); | |
$smon = date("m", $startTime)-1; | |
$sday = date("d", $startTime); | |
$syear = date("Y", $startTime); | |
$emon = date("m", $endTime)-1; | |
$eday = date("d", $endTime); | |
$eyear = date("Y", $endTime); | |
//pb=!1m8!1m3!1iYYYY!2iMM!3iDD!2m3!1iYYYY!2iMM!3iDD | |
//The Google Location history URL - gets the KML. | |
$locationURL = "https://www.google.com/maps/timeline/kml?authuser=0&pb=!1m8!1m3!1i".$syear."!2i".$smon."!3i".$sday."!2m3!1i".$eyear."!2i".$emon."!3i".$eday; | |
//To request the file, using PHP, we need to tell curl where the cookies are. | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $locationURL); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); | |
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); | |
$kml = curl_exec($ch); | |
curl_close($ch); | |
//get last gx:coord | |
$startIndex = strripos($kml,"<gx:coord>") + strlen("<gx:coord>"); | |
$endIndex = strripos($kml,"</gx:coord>"); | |
$substr = substr($kml, $startIndex, $endIndex - $startIndex); | |
$latlngArr = explode(" ",$substr); | |
$lng = $latlngArr[0]; | |
$lat = $latlngArr[1]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sadly Google API doenst support this method anymore.
Personally switched to using GpsLogger (open source)
https://github.com/mendhak/gpslogger/releases