Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
3/13/2010 3:19:17 PM EDT


I am using the Big Brother GPS software on my droid to send my current position to a server I have running at home.  The script works find but it doesn't pin point my location on the map with a marker.  Below is the script, is it possible to do what I want to do?



<?php



$name = "Scott";



$f = fopen("/tmp/position.cur", "r");

$p = fgets($f);



$p = explode(":", $p);



$time = $p[0];

$lat = $p[1];

$lon = $p[2];

$acc = $p[3];



$acc = (int)$acc;

$pos = "$lat,$lon";

$time = strftime("%Y-%m-%d %H:%M:%S", $time);

$utime = urlencode($time);

$uname = urlencode($name);



?>



<p>

 Latitude: <?=$lat?> <br />

 Longitude: <?=$lon?> <br />

 Accuracy: <?=$acc?> m<br />

 Updated: <?=$time?> <br />

</p>



<iframe width="640" height="480" frameborder="0" scrolling="no"

       marginheight="0" marginwidth="0"

       src="<a href="http://maps.google.com/?ie=UTF8&amp;q=Last+Update:+<?=$utime?>&lt;br&gt;Accuracy:+<?=$acc?>m(<?=$uname?>)@<?=$pos?>&amp;ll=<?=$pos?>&amp;z=13&amp;output=embed">http://maps.google.com/?ie=UTF8&amp;q=Last+Update:+<?=$utime?>&lt;br&gt;Accuracy:+<?=$acc?>m(<?=$uname?>)@<?=$pos?>&amp;ll=<?=$pos?>&amp;z=13&amp;output=embed</a>">

</iframe>



3/13/2010 3:22:46 PM EDT
[#1]
Post the contents of /tmp/position.cur so someone can test the script.z

3/13/2010 4:50:00 PM EDT
[#2]



Quoted:


Post the contents of /tmp/position.cur so someone can test the script.z





Sorry, I get the rest of the data posted here.  There is another script that the droid contacts to upload, that is posted below.



<?php



/* Get the position data from the POST parameters */

$lat = $_POST["latitude"];

$lon = $_POST["longitude"];

$acc = $_POST["accuracy"];



/* Write the position data to a file for the map script */

if ($lat && $lon && $acc) {

   $fcur = fopen("/tmp/position.cur", "w");



   $time = time();

   $out = "$time:$lat:$lon:$acc\n";



   fputs($fcur, $out);



   fclose($fcur);

}



?>





Here is what's odd.  The scripts didn't work until i created a tmp folder.  After creating the tmp folder the map started showing my local area along with all the lat, long, time, speed etc.  However, there is nothing ever in the tmp folder.  I update the location from the device and then check the folder immediately afterwards and there is nothing there.  I'm not expert but I don't see anything in the script that deletes the position.cur file.
 
3/13/2010 4:51:55 PM EDT
[#3]




<–– PHP ninja.



Tag, for when I'm sober.
3/13/2010 4:56:41 PM EDT
[#4]



Quoted:







<–– PHP ninja.



Tag, for when I'm sober.


DOH!  Come on man!  Get some coffee in you! :)



 
3/13/2010 4:58:47 PM EDT
[#5]



Quoted:





Quoted:






<–– PHP ninja.



Tag, for when I'm sober.


DOH!  Come on man!  Get some coffee in you! :)

 


I have a Droid, too. This looks cool, and kind of fun. I'll check back tomorrow. Right now, I just want to get drunk and listen to music.




 
3/13/2010 5:11:51 PM EDT
[#6]



Quoted:





Quoted:




Quoted:






<–– PHP ninja.



Tag, for when I'm sober.


DOH!  Come on man!  Get some coffee in you! :)

 


I have a Droid, too. This looks cool, and kind of fun. I'll check back tomorrow. Right now, I just want to get drunk and listen to music.


 


I figured you would like it.  I was using another piece of software but I didn't like the fact that my position was being sent to someone else's server.  I like having it go to a server that I control.





 
3/13/2010 5:14:37 PM EDT
[#7]
here is some code with a working map with pointer...  don't know if it will help...

http://zonehead.com/where.php
3/13/2010 5:27:21 PM EDT
[#8]



Quoted:


here is some code with a working map with pointer...  don't know if it will help...



http://zonehead.com/where.php


Looks like that is just a link to a google map with a static location.



 
3/13/2010 5:45:46 PM EDT
[#9]
When you upload files with php, it uploads to  a temp file.  If you don't then copy/move the temp file to another location, (move_uploaded_file) it disappears.
3/13/2010 6:27:52 PM EDT
[#10]



Quoted:


When you upload files with php, it uploads to  a temp file.  If you don't then copy/move the temp file to another location, (move_uploaded_file) it disappears.


Thank you for the info.  I'll have to dig up some code to do that.  After I figure out the marker on the map I wanted to figure out how to keep a few of the position.cur files in another directory.



 
3/13/2010 7:55:02 PM EDT
[#11]
Anyone else have any ideas?
3/14/2010 6:39:27 AM EDT
[#12]
Bump for when Subnet's hangover clears

3/14/2010 7:13:10 AM EDT
[#13]
function getMapCoordinates($mapDataRendered){
$url="http://maps.google.com/maps/geo?sensor=false&output=csv&key=".G_MAP_KEY."&q=".$mapDataRendered;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($ch);
curl_close ($ch);
return($data);
}

This is my own snipet for pulling coords from formatted addresses.

UPDATE: reread the question so not sure if this will help, we do have pinpoints on our displays so I can get you a example page with it up and running to examine the method.
3/14/2010 8:09:14 AM EDT
[#14]
Thanks for the info.  I'll have to look at it closely and see if I can figure it out.  I really need to run and grab a PHP book.






Quoted:


function getMapCoordinates($mapDataRendered){

$url="http://maps.google.com/maps/geo?sensor=false&output=csv&key=".G_MAP_KEY."&q=".$mapDataRendered;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

$data = curl_exec ($ch);

curl_close ($ch);

return($data);

}



This is my own snipet for pulling coords from formatted addresses.



UPDATE: reread the question so not sure if this will help, we do have pinpoints on our displays so I can get you a example page with it up and running to examine the method.






 
3/14/2010 8:22:47 AM EDT
[#15]
More than anything, I think it comes down to the formatting of this link to Google Maps





src="http://maps.google.com/?ie=UTF8&amp;q=Last+Update:+<?=$utime?>&lt;br&gt;Accuracy:+<?=$acc?>m(<?=$uname?>)@<?=$pos?>&amp;ll=<?=$pos?>&amp;z=13&amp;output=embed">






Also, I think that Java may need to be involved but I'm not positive.




 
3/14/2010 11:39:31 AM EDT
[#16]
Quoted:
The scripts didn't work until i created a tmp folder.

What?  Every UNIX system should already have a /tmp directory.  Even my Apple laptops have one.  Something is seriously wrong with your system if /tmp was missing.  Also, make sure /tmp has the correct permissions.  You may need to do a "chmod 777 /tmp" then "chmod +t /tmp".


Also, make sure you don't have safe_mode on:

http://www.php.net/manual/en/features.safe-mode.php

Even though I don't think that's the problem, it's something that will cause you headaches.z
3/14/2010 12:53:07 PM EDT
[#17]





Quoted:





Quoted:


The scripts didn't work until i created a tmp folder.



What?  Every UNIX system should already have a /tmp directory.  Even my Apple laptops have one.  Something is seriously wrong with your system if /tmp was missing.  Also, make sure /tmp has the correct permissions.  You may need to do a "chmod 777 /tmp" then "chmod +t /tmp".
Also, make sure you don't have safe_mode on:





http://www.php.net/manual/en/features.safe-mode.php





Even though I don't think that's the problem, it's something that will cause you headaches.cd





LOL, your post helped me pull my head out of my butt.  I had the script in /var/www/gps.  It wasn't working at first so I added a tmp folder to this location.  Everything started working after that so I moved on.  However, after reading your post I face palmed and realized that when the script said /tmp is was looking at the root of the filesystem and not the root of the folder where the script was executed. The contents of position.cur is below though modified to not give away my current position :)





1268599476:46.178200866666664:-1094451365:64.0


Time: Lat: Long: Accuracy





 
3/14/2010 2:24:06 PM EDT
[#18]
I wish I could see the output of the device.  It looks like different info is pulled from the device by the script.  I would like to see the raw output of the device.  I'm sure there is a way to do this with another PHP script.
3/14/2010 2:49:56 PM EDT
[#19]
Here are the current scripts that I have running if anyone is interested.  I was able to get the battery percentage up and am now working on the charging state.
bbg_recv.php
<?php

/* Get the position data from the POST parameters */
$lat = $_POST["latitude"];
$lon = $_POST["longitude"];
$acc = $_POST["accuracy"];
$bat = $_POST["battlevel"];
$crg = $_POST["charging"];

/* Write the position data to a file for the map script */
if ($lat && $lon && $acc && $bat) {
   $fcur = fopen("/tmp/position.cur", "w");

   $time = time();
   $out = "$time:$lat:$lon:$acc:$bat\n";

   fputs($fcur, $out);

   fclose($fcur);

}

?>

bbg_map.php










<META HTTP-EQUIV=Refresh CONTENT="30">
<?php

$name = "Scott";

$f = fopen("/tmp/position.cur", "r");
$p = fgets($f);

$p = explode(":", $p);

$time = $p[0];
$lat = $p[1];
$lon = $p[2];
$acc = $p[3];
$bat = $p[4];

$acc = (int)$acc;
$battery = (int)$bat;
$pos = "$lat,$lon";
$time = strftime("%Y-%m-%d %H:%M:%S", $time);
$utime = urlencode($time);
$uname = urlencode($name);


?>

<p>
 Name: <?$uname?> <br />
 Latitude: <?=$lat?> <br />
 Longitude: <?=$lon?> <br />
 Accuracy: <?=$acc?> m<br />
 Updated: <?=$time?> <br />
 Battery Level: <?=$battery?>%<br />
</p>



<iframe width="640" height="480" frameborder="0" scrolling="no"
       marginheight="0" marginwidth="0"
       src="http://maps.google.com/?ie=UTF8&amp;q=Last+Update:+<?=$utime?>&lt;br&gt;Accuracy:+<?=$a$
</iframe>

Contents of position.cur
Formatted in, Time: Latitude: Longitude: Accuracy In Meters: Battery Life Percentage






1268606543:48.17820163333333:-101.84451631666667:24.0:30
My goals



  • Keep the last 200 position logs [I'm sure there is a better way to do this in PHP but right now I setup a shell script to move and rename the files.  I'll run that occasionally with crontab.  I'd like to know how to accomplish the same thing with PHP though.]




  • Get the Charge State to appear



  • Get marker to appear on the map.







 
4/24/2010 11:25:47 AM EDT
[#20]
Well I had a few other things come along and this project was moved to the back burner.  This morning I was able to take a fresh look at it and was able to knock it out fairly easily.  The main problem was that I was improperly calling the variables into the Google Maps link.  If you want to track your phone or allow others to track you and want the privacy of your own server this is the way to go.  If you have any questions don't hesitate to ask.  



I've included the code for both pages below.







<meta http-equiv="content-type" content="text/html; charset=utf-8"></meta>


bbg_recv.php


<?php

/* Get the position data from the POST parameters */
$lat = $_POST["latitude"];
$lon = $_POST["longitude"];
$acc = $_POST["accuracy"];
$bat = $_POST["battlevel"];
$crg = $_POST["charging"];

/* Write the position data to a file for the map script */
if ($lat && $lon && $acc && $bat) {
   $fcur = fopen("/tmp/position.cur", "w");

   $time = time();
   $out = "$time:$lat:$lon:$acc:$bat\n";

   fputs($fcur, $out);
   
   fclose($fcur);
       
}

?>





bbg_map.php


<META HTTP-EQUIV=Refresh CONTENT="30"> 
<?php

$name = "Scott";

$f = fopen("/tmp/position.cur", "r");
$p = fgets($f);

$p = explode(":", $p);

$time = $p[0];
$lat = $p[1];
$lon = $p[2];
$acc = $p[3];
$bat = $p[4];

$acc = (int)$acc;
$battery = (int)$bat;
$pos = "$lat,$lon";
$pos2 = "$lat,+$lon";
$time = strftime("%Y-%m-%d %H:%M:%S", $time);
$utime = urlencode($time);
$uname = urlencode($name);


?>

<p>
 Name: <?$uname?> <br />
 Latitude: <?=$lat?> <br />
 Longitude: <?=$lon?> <br />
 Accuracy: <?=$acc?> m<br />
 Updated: <?=$time?> <br />
 Battery Level: <?=$battery?>%<br />
</p>


       
         
<iframe width="640" height="640" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=<?=$pos?>&amp;sll=<?=$pos?>&amp;sspn=0.006799,0.018024&amp;ie=UTF8&amp;ll=<?=$pos?>&amp;spn=0.006799,0.018024&amp;z=14&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=<?=$pos?>&amp;sll=<?=$pos?>&amp;sspn=0.006799,0.018024&amp;ie=UTF8&amp;ll=<?=$pos?>&amp;spn=0.006799,0.018024&amp;z=14" style="color:#0000FF;text-align:left">View Larger Map</a></small>








Close Join Our Mail List to Stay Up To Date! Win a FREE Membership!

Sign up for the ARFCOM weekly newsletter and be entered to win a free ARFCOM membership. One new winner* is announced every week!

You will receive an email every Friday morning featuring the latest chatter from the hottest topics, breaking news surrounding legislation, as well as exclusive deals only available to ARFCOM email subscribers.


By signing up you agree to our User Agreement. *Must have a registered ARFCOM account to win.