Last week Google released a version of Latitude for the iPhone. Unfortunately it’s a web page that you have to visit every time you want to update your location.
In my opinion, it would be nicer to have my iPhone automatically update my location in the background without having to visit google.com/latitude every time I want to let my friends know that I’ve moved.
So this weekend I wrote a script that does just that.
I call it playnice. Run it in cron to keep Latitude apprised of your iPhone’s location.
Update: Andy Blyler has taken over maintenance of playnice, so the link above now points to his playnice github project.
It works by scraping the iPhone location from MobileMe’s Find My iPhone feature, using the code from Tyler Hall’s sosumi project. When you enable Find My iPhone, your iPhone will regularly send its location to MobileMe.
Google doesn’t provide an API to update Latitude yet, so there is some scraping involved on that end too. Thanks to Jack Catchpoole for his help with the Google scraping.
Of course, you need a MobileMe subscription for this to work.
With all the scraping, playnice could be fragile and subject to any minor changes Google and Apple might make.
It would be nice if Google and Apple would offer APIs for these services in the future.
But at least for now, it works.
Posted on 2 August 2009
- Leave a comment
- Subscribe with Google Reader
- Follow me on Twitter
Did you like this article?
-
Thanks, nice to know. I have a couple friends with iPhones that may be interested. On the other side, it’s all automatic and well integrated in android phones
-
Clever. I may have to push this on my iPhone-using friends as well. My poor G1 has a fresh list of other Android and Blackberry users, and then a trailing list of several-day-old locations of iPhones. Thanks!
-
Nat, I can see from the reflection of the Lego mini-figure that you took this picture naked
-
you made me look to the original size.
-
-
I second Alex’s request for some basic info on how to use this.
Please & Thank You!
-
Super easy to use,
Just run from command line:
php5 /path/to/playnice.php
it will ask you some questions the first time and should work fine.. make sure you have php5 and php5-curl installed.
the part that perplexes me is that when i run it in cron the google cookie file never updates!!!?? only when i run manually.. any ideas??
-
Ok. little closer. when i run it in cron it’s reasking for the login info.. no way to specify it though, trying to find the path it’s looking for now to drop the pass file in there.
-
Got it..
here’s how to do it:
make a bash script:
#!/bin/bash
cd /home/user/www/Latitude
/usr/bin/php5 ./playnice.phpthen your cron should look like this:
* * * * * /home/user/www/Latitude/run > /home/user/www/Latitude/error.log
The above pipes the output into an error file , i used this to debug once you have it working you can remove it.. be sure to have already ran it once manually , and change the paths above to your dirs.
-
Awesome script – got it working first time.
Thanks!
-
Can someone please give a guide as to what to download, how to install
I really have no idea what any of this code stuff means cron etc
Thank you
-
Adam.. You can goto
http://github.com/natfriedman/playnice/tree/master
And click the download button…
Choose zip and extract it to your server…
Make sure you have PHP5 installed if you’re using ubuntu you can run
sudo apt-get install php5 php5-curl
Then you can run the script by going into the directory and typing:
php5 playnice.php
It will ask you some questions like your username and passwords for mobile me and google, then it will write 2 files..
The first file is the cookie used to update google with your locaiton , the other is your username and passwords stored in it (encrypted i’m sure, but haven’t checked).
To make this run automatically, you can make a file in the directory for example called “run” in that file put the following:
#!/bin/bash
cd /home/user/www/Latitude
/usr/bin/php5 ./playnice.phpSave it and chmod it to 755 and +x
run the script to make sure it works..
./run
You should get some feedback on the screen just like when you ran php playnice.php..
now you type
crontab -e
to edit your crontab (your auto runs)
Put this in the file on its own line:
* * * * * /home/user/www/Latitude/run > /dev/nulland save.. ( :wq! if using vi as your editor)
It will now update your location every minute..
-
-
One thing I’ve noticed with this script.. Mobile Me doesn’t just check every so often. It appears that every time you ask mobile me for the location, it polls the device.. I had mine updating every minute over night, and my charger couldn’t keep up with the battery usage..
Just a warning.. You may want to have your script check every 15 minutes etc.
-
hi Bikr, i am looking in the files for that, but have you found the place or right file to adjust the polling time?
kind regards,
Ivan
-
found it, it’s the cronjob.
-
-
-
I just tried loading this up on one of my servers.
I enter my MobileMe username (tried with @me.com and without) and Google password. It fetches the Google Session cookie find, and attempts to get the iPhone location. It seems to get it fairly quickly, but then in iPhone Location it says ” , ” (excluding quotes)
It when proceeds to update Latitude with nothing
Cheers
Dave-
Just to add:
I’ve done some tests and by the look of it the Sosumi class isn’t retrieving the devices properly. On my account it gets 0. I do have a MobileMe family pack so maybe that has something to do with it. The Sosumi call on line 149 (curlPost) seems to return nothing.Anyone got any ideas?
-
I have the same problem and I also have the family pack.
I have apt-get install’d ca-certificates – do I need to configure it or something?
-
trying to run it using php 5.3 on my winxp machine, i get…
’stty’ is not recognized as an internal or external command,
operable program or batch file.
[ Lots of other errors removed by editor ... ]
-
-
-
Is there any way to set this up without SSH/telnet access to the server? My host gives me access to cron through cpanel, but no SSH access. I tried manually creating the mobileme password text file, but then it was asking about the cookie file or whatever. is there anyway to manually get those values and plug them into the setup files, or do i have to run the PHP file from the server to complete setup?
-
if you’re in a country where the igoogle latitude widget isn’t available, append “?gl=us” to the end of the url on line 22 of class.google.php
-
Hi Nat, thanks for the script. I also have to do it local before loading it up to my part on the webserver of my host.
But do i have to do something extra locally. because running the: sudo apt-get install php5 php5-curl in the directory where youre files are, it says: apt-get – command not found, do i have to install php5 and ubuntu on the mac?Kind regards and many thanks!
Ivan -
Any one out htere ho managed to get it installed (the first part before uploading the script to a webserver) on a Mac?
Could someone please help me out with it, downloaded Mamp, Fink but can not get past that apt-get command.Kind regards,
Ivan
-
a bit further, installed ubuntu under vmware and got the cookies, busy on the second part, also not so easy for not insiders
ivan
-
Ivan, any luck getting it to run in Ubuntu?
-
hi nathan yes i did, ubuntu was the easiest way for me.
ivan
-
but something else is happening. in the root it makes a file called playnice.php.1 and so on till what i saw today playnice.php.485, is there a way i can put this out or is it the way i made the cronjob that makes the file??
cronjob command is:
/usr/bin/wget /dev/null http://www.doman.com/directory/playnice.php-
-
thanks Frederik, that worked!!
toppie!ivan
-
-
-
-
-
-
Has anyone been able to resolve the issue regarding the “iPhone Location: , ” error message? I’m running Ubuntu with PHP5 and ca-certificates installed. I got it working on my Mac, but I would like it to run all the time on my Ubuntu Desktop.
-
Any chance step by step instructions for newbies could be posted?
Judging from the comments getting this to work requires hosting the files and running them on a server. Is that right? These are the kinds of things I’d love covered in a howto.
Either way it’s great to see this functionality is possible.
-
It seems like the error many people are seeing is caused by either an incopatibility with PHP 5.2 or the older cURL module installed in Debian/Ubuntu.
This is how I fixed it:
I added these two lines to /etc/apt/sources.listdeb http://php53.dotdeb.org stable all
deb-src http://php53.dotdeb.org stable allThen I did an
apt-get update && apt-get dist-upgradeBe warned: PHP 5.3 may brake your webservers PHP setup.
-
This fixed it for me. I’m getting some other errors now, but it still updates the iPhone location. Thanks!
-
-
Sounds nice. I would suggest to add an option to sync Fire Eagle location to Google Latitude. I think it should be possible to fetch the location from Fire Eagle with php and then update to Google Latitude like in this script. Or should I do it if I have time to do it?
This would allow me to update my location with Navizon to Fire Eagle which would then update my Latitude location. On jailbroken iPhones you can install Navizon from Cydia which is able to update the location in the background every 10 minutes. Navizon is also availabe from iTunes Store but without the background update.
And, if you are new to Navizon and you register you can put my referral code 565E585B595B so I get some points
-
I’m having the same problem with no iphone location
Runnin PHP 5.2.8 on a public web server – any tips to get this working?
Cheers
Simon
-
Ah – got it working – hadn’t enabled findmyiphone feature on the iphone!
-
simon are you also getting alllll the playnice.php.1 ….. files in the root of your directory after succesfull location tracing?
kind regards.
ivan
-
-
Has anyone figured out how to do something similar without a subscription to MobileMe?
I’ve jailbroken my iPhone and know how to run scripts directly on it. Is there a command-line way on the iPhone terminal to get my current location? If there is, then I could probably figure out the rest.
Thanks in advance,
Steve -
Nat – Just a quick thank you!~ This is exactly what I was looking for to allow me to track my family’s iphones. Especially with the Latitude piece, all I have to do is go to Latitude on my iPhone and have an instant update where everyone (well, at least their iphones anyhoo) is located.
Made a few modifications to your excellent script to accept some cmd line args for the different members of the family, placed into cron on the iMac and we are in business.
The last piece I want to do is add a Growl notification >Prowl so I can be sure the kids are at home after school with a scheduled Notification and AT&T “Track family members” can kiss my arse!
Thanks again!
-
Could you please post your cmd line args changes? That’s exactly what I need and my PHP skillz are definitely not 7334!
-
-
could just be me, but i think this may have been broken with some of the recent changes to mobileme. anyone else having problems?
-
Yep, looks like it broke after they performed the maintenance last night. Bummer…
-
Would it be possible to set it up so that it sends out your position automatically every hour if your speed is less than 10 mph, but when it goes over 10mph it would do it every 30 seconds or so? That would save alot of battery life.
-
-
It looks like updating via the iGoogle widget is failing now. I took this as motivation to update playnice to use the mobile Google Latitude site for updating. Feel free to try my code out at: http://github.com/ablyler/playnice
-
Anyone tried this script with a single user account that’s enabled on more than one iPhone? I have a trial account that I enabled on mine and my wife’s iPhones so when I go to the Find My iPhone page I see both devices under my single user trial account. How does the script determine which iPhone to scrape from? Many thanks!!!
-
Does anyone else get
Fatal error: Uncaught exception ‘Exception’ with message ‘Error during POST of ‘https://secure.me.com/device_mgmt/en’: Failed to open/read local data from file/application’ in …. class.sosumi.php:226
I’m trying to figure out why this error is caused but I’m not making much progress.
-
I don’t see an exception but it’s not getting the location at all.
-
I lied. It looks like it’s working.
Are you using the latest version from Andy’s GitHub repo?
-
-
-
FYI Andy was kind enough to set up a Google Group to discuss the playnice project:
http://groups.google.com/group/playnice-developers
See you there!
-
Anyone hear of a Windows version/patch?
-
I would like to run this on my Macbook, but have no idea what I’m doing. Nice idea though. Is it possible to compress this into an executable file that you could just download and run?
-
This script is awesome! Thank you Everybody.
Set this up on my www server under it’s own folder and it runs great.
Just one question. the google-password.txt and mobileme-password.txt are scary.
I’ve chmod 700 the playnice folder
and i see those files are 600
so is that everything? or can those files still be accessed or read by a bad guy or the spiders?
answers appreciated!


78 comments