| Reply | « Previous Thread | Next Thread » |
|
There are several programs around capable of tracking a phone via GPS, but looks like all of them require "free subscription" to some services, or they only allow tracking through GoogleMaps, or just export KML files to be manually loaded into GoogleEarth.
Boring. I have a better idea: I publish the source of a PHP script which anyone can store on any server he likes, possibly a free hosting service (which must support PHP, such as www.altervista.org ). This script receives position data from a program installed on your phone, which can be: LCCarTrack Trakkcor Script for LCCarTrack: Code:
<?php
// This file is part of LcCarTrack project by Luca Cassioli
//
// This file receives data from an URL and stores them into a KML file
// for vieweing in GooglEarth compatible programs.
//
// URL example:
// http://jumpjack.altervista.org/lccartrack/upload.php?pos=12.0,42.01&name=Auto&speed=12&time=2008-10-22_10:10:10
// Single position kml file
$filename = 'lccartrack.kml';
$handle = fopen($filename, 'w');
// Logger file
$history = 'lccartrack.txt';
$handle2 = fopen($history, 'a+');
// Get the data from the POST request
$time = date('Y-m-d H:i:s');
$name = $_GET['name'];
$pos = $_GET['pos'];
$speed = $_GET['speed'];
$GPSTime = $_GET['time'];
// Setup kml portions
$kmlHeader='<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Folder><description>MGMaps Favorites</description><name>MGMaps Favorites</name><visibility>1</visibility><open>1</open><Placemark>';
$kmlNameHeader='<name>';
$kmlName=$name;
$kmlNameFooter='</name>';
$kmlDescriptionHeader='<description>';
$kmlDescription='Phone:' . $time . "\nGPS:" . $GPSTime;
$kmlDescriptionFooter='</description>';
$kmlPositionHeader='<Point><coordinates>';
$kmlPosition=$pos.substr(5,$pos.length-1);
$kmlPositionFooter=',0</coordinates></Point>';
$kmlFooter='</Placemark></Folder></kml>';
// Send data back to the phone
echo 'Dati ricevuti:<br>';
echo $name . '<br>';
echo $pos . '<br>';
echo $speed . '<br>';
echo $GPSTime . '<br>';
$output = $name . ',' . $pos . ',' . $speed . ',' . $GPSTime .chr(13) . chr(10);
echo '>>>>>>' . $output . '<<<<<<';
// Write data to log file
fwrite($handle2, $output, strlen($output));
// Write data to KML file
fwrite($handle, $kmlHeader, strlen($kmlHeader));
fwrite($handle, $kmlNameHeader, strlen($kmlNameHeader));
fwrite($handle, $kmlName, strlen($kmlName));
fwrite($handle, " - ", 3);
fwrite($handle, $speed, strlen($speed));
fwrite($handle, " Km/h", 5);
fwrite($handle, $kmlNameFooter, strlen($kmlNameFooter));
fwrite($handle, $kmlDescriptionHeader, strlen($kmlDescriptionHeader));
fwrite($handle, $kmlDescription, strlen($kmlDescription));
fwrite($handle, $kmlDescriptionFooter, strlen($kmlDescriptionFooter));
fwrite($handle, $kmlPositionHeader, strlen($kmlPositionHeader));
fwrite($handle, $kmlPosition, strlen($kmlPosition));
fwrite($handle, $kmlPositionFooter, strlen($kmlPositionFooter));
fwrite($handle, $kmlFooter, strlen($kmlFooter));
fwrite($handle, "\n");
fclose($handle);
?>
Code:
<?php
// This file is part of LcCarTrack project by Luca Cassioli
//
// This file receives data from an URL and stores them into a KML file
// for vieweing in GooglEarth compatible programs.
//
// URL example:
// http://jumpjack.altervista.org/lccartrack/trakkcor_upload.php?position=$GPGGA,075202.000,4156.2585,N,01236.6349,E,1,05,3.1,52.8,M,45.9,M,,0000*6C&deviceID=name
// Single position kml file
$filename = 'trakkcor.kml';
$handle = fopen($filename, 'w');
// Logger file
$history = 'lccartrack-trakkcor.txt';
$handle2 = fopen($history, 'a+');
// Get the data from the POST request
$time = date('Y-m-d H:i:s');
$name = $_GET['deviceID'];
$pos = $_GET['position'];
$speed = $_GET['speed'];
$GPSTime = $_GET['time'];
$latintstr=substr($pos,18,2); // first two chars = degrees
$latint = (int)$latintstr;
$latdecstr=substr($pos,20,7); // remaining chars = decimal minutes (mm.mmmm).
$latdec=((float)$latdecstr)/60;
$latAll=$latint + $latdec; // Sum integer and float parts (result in decimal degrees).
$lonintstr=substr($pos,30,3); // first two chars = degrees
$lonint = (int)$lonintstr;
$londecstr=substr($pos,33,7); // remaining chars = decimal minutes (mm.mmmm).
$londec=((float)$londecstr)/60;
$lonAll=$lonint + $londec; // Sum integer and float parts (result in decimal degrees).
$GPSTime = substr($pos,7,2) . ':' . substr($pos,9,2) . ':' . substr($pos,11,2);
// Setup kml portions
// $GPGGA,075202.000,4156.2585,N,01236.6349,E,1,05,3.1,52.8,M,45.9,M,,0000*6C
$kmlHeader='<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Folder><description>MGMaps Favorites</description><name>MGMaps Favorites</name><visibility>1</visibility><open>1</open><Placemark>';
$kmlNameHeader='<name>';
$kmlName=$name;
$kmlNameFooter='</name>';
$kmlDescriptionHeader='<description>';
$kmlDescription='Phone:' . $time . "\nGPS:" . $GPSTime;
$kmlDescriptionFooter='</description>';
$kmlPositionHeader='<Point><coordinates>';
$kmlPosition = $lonAll . ',' . $latAll;
$kmlPositionFooter=',0</coordinates></Point>';
$kmlFooter='</Placemark></Folder></kml>';
// Send data back to the phone
echo 'Dati ricevuti:<br>';
echo $name . '<br>';
echo $pos . '<br>';
echo $speed . '<br>';
echo $GPSTime . '<br>';
// Write data to log file
$output='Ricevuto:' . $pos . chr(13) . chr(10);
fwrite($handle2, $output, strlen($output));
$output = $name . ',' . (string)$latAll . ',' . (string)$lonAll . ',' . $GPSTime . chr(13) . chr(10);
fwrite($handle2, $output, strlen($output));
// Write data to KML file
fwrite($handle, $kmlHeader, strlen($kmlHeader));
fwrite($handle, $kmlNameHeader, strlen($kmlNameHeader));
fwrite($handle, $kmlName, strlen($kmlName));
fwrite($handle, " - ", 3);
fwrite($handle, $speed, strlen($speed));
fwrite($handle, " Km/h", 5);
fwrite($handle, $kmlNameFooter, strlen($kmlNameFooter));
fwrite($handle, $kmlDescriptionHeader, strlen($kmlDescriptionHeader));
fwrite($handle, $kmlDescription, strlen($kmlDescription));
fwrite($handle, $kmlDescriptionFooter, strlen($kmlDescriptionFooter));
fwrite($handle, $kmlPositionHeader, strlen($kmlPositionHeader));
fwrite($handle, $kmlPosition, strlen($kmlPosition));
fwrite($handle, $kmlPositionFooter, strlen($kmlPositionFooter));
fwrite($handle, $kmlFooter, strlen($kmlFooter));
fwrite($handle, "\n");
fclose($handle);
?>
Second script stores data in trakkcor.txt and trakkcor.kml files. These KML files have been tested on GoogleEarth and they works. They should also work in MGMaps and J2MEMaps on phone... but currently they don't (investigating...). LCCarTrack is written in python by me... thats' why this message has been posted here. ![]() Trakkcor is a j2me midlet. == DISCLAIMER == Please keep in mind that data you upload to my server will be publicily available and will reveal your position.
Last edited by cassioli : 2008-10-28 at 16:41.
|
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Rafael T.
Offline
Forum Nokia Champion
|
|
I have already said in your other post, but I must repeat:
Great idea, great implementation, great example, great application! ![]() BR, Rafael. |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |