You Are Here:

Community: Developer Discussion Boards

#1 Old [announce]Free real time GPS tracking on GoogleEarth and Cellphone - 2008-10-28, 16:33

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
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);  
    ?>
Script for Trakkcor:
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);  
    ?>
First script stores data in lccartrack.txt (history) and lccartrack.kml (current pos) files in its same folder.

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.
Reply With Quote

#2 Old Re: [announce]Free real time GPS tracking on GoogleEarth and Cellphone - 2008-10-28, 16:37

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia