How to check that $status came against from which location (bounding box)?

50 views
Skip to first unread message

sohail....@gmail.com

unread,
Apr 19, 2013, 1:23:21 AM4/19/13
to phireho...@googlegroups.com

Hi all,

    public function enqueueStatus($status) {
      $tweet_object = json_decode($status);
      var_dump($tweet_object);
    }

After successful run of code, when get $status in above function. How to check that $status came against from which location?

Simply I want to get location value with $status

like

this $status came against "-122.75, 36.8, -121.75, 37.8"

       $stream->setLocations(array(
           array(-122.75, 36.8, -121.75, 37.8), // San Francisco
           array(-74, 40, -73, 41), // New York
      ));
See on  github https://github.com/fennb/phirehose/pull/1#issuecomment-16572459

Fenn Bailey

unread,
Apr 19, 2013, 1:59:47 AM4/19/13
to phireho...@googlegroups.com
According to twitters documentation, the matched tweets should have either a:


If you like, you could paste the dump of the matched status?

Cheers,

  Fenn. 




--
 
---
You received this message because you are subscribed to the Google Groups "Phirehose Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phirehose-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

sohail....@gmail.com

unread,
Apr 19, 2013, 3:24:37 AM4/19/13
to phireho...@googlegroups.com
Thanks for reply fennb.

I don't want to look in the tweet object for boundingbox. The boundingbox that is in the tweet object tells that this tweet posted within "this bounding box".

Now I porvide the boundingbox of whole country like UnitedStates and UnitedKingdom to setLocations().
 $stream->setLocations(array(
           array(-178.214203,	18.536892, -48.466812,71.406647), // United States 
 	   array(-8.164723, 49.955269,	1.7425,	60.6311)          // United Kingdom 	
      ));


I want to get back both the boundingbox and tweet LIKE in following function.

 public function enqueueStatus($status) {
      $tweet_object = json_decode($status);
      $bounding_box = $tweet_object->boundingbox;
$tweet = $tweet_object->tweet; }
If you think it is not for all users of phirehose but only for in my case. Then please provide solution how can I do that Or make change for all users of phirehose.
Thanks

Fenn Bailey

unread,
Apr 19, 2013, 3:31:40 AM4/19/13
to phireho...@googlegroups.com
Hi there,

Sorry, I may not have been very clear with my earlier message - what I meant was, the object you get back (tweet_object in your example) should already have either a coordinates or place attribute (which has coordinates of its own) as part of the object.

Once you have the coordinates of the tweet, you can work out which bounding box it falls into, simply by looking at the lat/long. Does that make sense?

If you can post the print_r output of the status that matched, I can show you what I mean.

Cheers,

  Fenn.

Darren Cook

unread,
Apr 19, 2013, 3:58:13 AM4/19/13
to phireho...@googlegroups.com
> I want to get back both the boundingbox and tweet LIKE in following
> function.
>
> public function enqueueStatus($status) {
> $tweet_object = json_decode($status);
> $bounding_box = $tweet_object->boundingbox;
> $tweet = $tweet_object->tweet;
> }

That is basically how it works, though I don't think it is called
boundingbox.
To see what fields (during development) you have, change your code to:

public function enqueueStatus($status) {
$tweet_object = json_decode($status);
print_r($tweet_object);
}

A quick scan of some raw json I have here shows it might look like this:

"geo":{"coordinates":[39.5721,-119.7976],"type":"Point"}

For people without that information you see:
"geo":null

Darren


--
Darren Cook, Software Researcher/Developer

http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)

sohail....@gmail.com

unread,
Apr 19, 2013, 5:50:13 AM4/19/13
to phireho...@googlegroups.com
@fennb Once you have the coordinates of the tweet, you can work out which bounding box it falls into, simply by looking at the lat/long. Does that make sense?


Ok great I will do work out for which bounding box it falls into


Thanks

sohail....@gmail.com

unread,
Apr 19, 2013, 8:20:53 AM4/19/13
to phireho...@googlegroups.com, sohail....@gmail.com

Hi, I have just created a function that check if "latitude and longitude exists in the bounding box".
Please check if you think to improve this function so provide me instructions OR find a bug so report me.
I ll be very thankfull to you.
<?php

$lat = '62.94900';
$lng = '-149.34100';

$bounding_boxes = array(
array('-8.164723, 49.955269, 1.7425, 60.6311','UK'),
array('-178.214203, 18.536892, -48.466812, 71.406647','US')
);

function check_lat_lng_in_boundingBox( $bounding_boxes, $lat, $lng ) {

$result = '';
foreach ($bounding_boxes as $bounding_box) {
$bB = $bounding_box[0];
$bBArea = $bounding_box[1];
$bB_parts = explode(',', $bB);
//extract long bounding parts
$west_long = $bB_parts[0];
$east_long = $bB_parts[2];
$cmp_long =  ($west_long > $east_long) ? 'to':'from';
$exists = array();
//check longitude exists or not in long bounding parts
if ($cmp_long == 'to') {
if ( $lng > $east_long && $lng < $west_long ) {
$exists['long'] = 'yes';
}
else {
$exists['long'] = 'no';
}
}
else {
if ( $lng > $west_long && $lng < $east_long  ) {
$exists['long'] = 'yes';
}
else {
$exists['long'] = 'no';
}
}
//extract lat bounding parts
$north_lat = $bB_parts[1];
$south_lat = $bB_parts[3];
$cmp_long =  ($north_lat > $south_lat) ? 'to':'from';
//check latitude exists or not in lat bounding parts
if ($cmp_long == 'to') {
if ( $lat > $south_lat && $lat < $north_lat ) {
$exists['lat'] = 'yes';
}
else {
$exists['lat'] = 'no';
}
}
else {
if ( $lat > $north_lat && $lat < $south_lat  ) {
$exists['lat'] = 'yes';
}
else {
$exists['lat'] = 'no';
}
}

if ( $exists['long'] == 'yes' && $exists['lat'] == 'yes' ) {
$result = $bounding_box;
break;
}
else {
continue;
}
}//end foreach
if ($result == '') {
return 'out of range';
}
else {
return $result;
}
}


var_dump(check_lat_lng_in_boundingBox( $bounding_boxes, $lat, $lng ));

//result
/*
array (size=2)
  0 => string '-178.214203, 18.536892, -48.466812, 71.406647' (length=45)
  1 => string 'US' (length=2)*/



Reply all
Reply to author
Forward
0 new messages