Ok…. so i’m not a rich guy to afford a iPhone, blackberry or an Android (but i’ts on the wishlist) so i made a little programing… yeah.
Well the ideea is quite simple: get the Google Latitude Latitude and Longitude them send them to 4sqr, after that check for nearby venues…. then check in in the appropriate one:
Let’s begin:

i searched for a phpclass as a base… and found this one witch is a little buggy so i had to do some quick fixes:
now: index.php

include "kernel/foursquare.class.php";
include "kernel/latitude.php";
include "conf/conf.php";
$foursquare = new Foursquare($phone, $pass);
$foursquare->format = "json";
$json = $foursquare->nearbyAndSearch($l, $lo,"30","");
$where = json_decode($json, true);

foreach ($where['groups'] as $element){
		foreach ($element['venues'] as $venues){
				$nume = $venues['name'];
				$id = $venues['id'];
				$dist = $venues['distance'];
				echo "<a href='check.php?id=$id'>$nume</a> - $dist m<br />" ;
				}
}

This thing does the searching for the venues and lists them. then send’s them
check.php – the file

include "kernel/foursquare.class.php";
include "conf/conf.php";
$foursquare = new Foursquare($phone, $pass);
$foursquare->format = "json";
$id = $_GET['id'];
$check = $foursquare->checkin($id,"","","","1","1","","");

$checkr = json_decode($check, true);
echo "<pre>";
var_dump($checkr);

Yeah, the output rocks :)

so next in line is the how to get the code the Latitude and Longitude from Google Latitude:

function open($url_page)
	{
    $ch = curl_init($url_page);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Google");
    curl_setopt ($ch, CURLOPT_URL, $url_page );
    $html = curl_exec ( $ch );
    curl_close($ch);
    return $html;
	}
	
	
$xml = open("http://www.google.com/latitude/apps/badge/api?user=-$latidude_code&type=iframe&maptype=roadmap&z=15");
//echo '<pre>';


$datePattern = '^latitude_e6=([0-9]+)^';
preg_match($datePattern, $xml, $matches);
$lat = $matches[1];

$datePattern2 = '^longitude_e6=([0-9]+)^';
preg_match($datePattern2, $xml, $matches2);
$long = $matches2[1];

// the simple way :')
// make the latitude xx.xxxxx
$l .= $lat[0]; 
$l .= $lat[1];    
$l .= ".";
$l .= $lat[2];    
$l .= $lat[3];    
$l .= $lat[4];    
$l .= $lat[5];    
$l .= $lat[6];    
$l .= $lat[7];
$l .= $lat[8];

// make the longitude yy.yyyyy
$lo .= $long[0];  
$lo .= $long[1];    
$lo .= ".";
$lo .= $long[2];    
$lo .= $long[3];    
$lo .= $long[4];    
$lo .= $long[5];    
$lo .= $long[6];    
$lo .= $long[7];
$lo .= $long[8];

and the last
config.php

$phone = ""; // phone #
$pass = ""; // password 
$latidude_code = ""; //get the code from the http://www.google.com/latitude/apps/badge, you need to have it shared on street level, exluclude the - sign  

and here is at Google Code

cheers

If this has been useful you should give me a beer

13 responses


Do you want to comment?

Comments RSS and TrackBack Identifier URI ?

I change conf.php, and put all files in a web server.
but there show “Warning: Invalid argument supplied for foreach() in /xxxxxxx/4sqr/index.php on line 14″
I dont know how to do then

6 June 2010 14:24

the error is from google, did you set correctly the Latitude ID ?

6 June 2010 14:26

….api?user=-7435672108789605184&type=iframe&maptype=roadmap&z=10
$latidude_code = “7435672108789605184″;
is it right?

6 June 2010 14:31

ok, maybe there are no venues in your area, try to add one for a test…
anyway, if that does not work try to edit this line:

$json = $foursquare->nearbyAndSearch($l, $lo,"30","");

and modify $l and $lo to the long and lat you are close… try that and tell me if it works

i need to do another version of the script anyway :)

cheers

6 June 2010 15:05

ok. I will try.
there also have 3 point what I havent know clearly
1. in conf.php
$phone = “(918)716-6167″;
OR
$phone = “9187166167″;
and can I write my email address here?
2.4sq was blocked in China
It sucks
so I need go to my school to test venues
3. In china, google maps wasnt very exact correctly
It always has 500 meters distance from where I stand
and I didnt know change $l $lo to how

6 June 2010 15:58

dude, $phone = “”; is your login phone from foursquare. yeah i know the great firewall of china banned foursquare but you know your server needs out of china :)

7 June 2010 18:04

I think many people login 4sq use email not phone, especially in China。。。
And my server locate in USA, so I can easy through GFW with it
But….. I still can not use it….
http://173.208.147.252/4sqr/

8 June 2010 10:30

when I svn up
I found I can use it
BUt but there is not my location…
I’m in 120,30
but this said I’m in 44.5,26
I have checked my $latidude_code is right

10 June 2010 07:26

don’t know mate…. i’ve tried, sorry

7 July 2010 01:09

never mind
In svn r5 there has some error
kernel/latitude.php
$google_json = open(“http://www.google.com/latitude/apps/badge/api?user=-$latidude_code&type=json”);
but some time, when i check in, it says null. some times it’s fine

7 July 2010 01:46

maybe is from your server trying to connect to the Google link, you should modify the curl time out to 20 seconds or somthing like that

2 August 2010 08:31


hi, i’m andrea an italian developer.
i discovered this article about foursquare, and i’m going to make you a request.
i would like to get all venues/checkins/tips of a given location (a couple of lat, long coords) within a given radius. how can i do that?

thank you in advance!
A. :)

21 July 2011 21:58

Comment now!