Cree
asked on
Twitter API JSON GEOCODE
I'm grabbing data off of twitter and need help with obtaining geo coordinates (if exist)
currently, what i'm doing is
not null:
null:
how how should i set up my $dirArray[$i][1] = $decode->results[$i]->
to get geo whether it's null or not?
I've tried
$dirArray[$i][8] = $decode->results[$i]->geo;
and putting it into a varchar.. but that doesn't work since at times it's an array.
Any help please!!!
currently, what i'm doing is
$l = count($decode->results);
for ($i=0; $i < $l; $i++) {
$dirArray[$i][0] = $decode->results[$i]->text;
$dirArray[$i][1] = $decode->results[$i]->from_user;
I'd like to grab geo also but .. sometimes Geo is Null and other times it's an array.not null:
"geo":{"coordinates":[33.045491,-96.731439],"type":"Point"},
null:
,"geo":null,
how how should i set up my $dirArray[$i][1] = $decode->results[$i]->
to get geo whether it's null or not?
I've tried
$dirArray[$i][8] = $decode->results[$i]->geo;
and putting it into a varchar.. but that doesn't work since at times it's an array.
Any help please!!!
ASKER
ok.. thanks
I'm a little further
I now have a variable ($j) that contains an array. when I dump it, it gives me this:
If I wanted to assign each array to a variable.. say $y and $z.. how would I go about doing it?
I'm a little further
I now have a variable ($j) that contains an array. when I dump it, it gives me this:
object(stdClass)#252 (2) { ["coordinates"]=> array(2) { [0]=> float(-22.904169) [1]=> float(-43.177224) } ["type"]=> string(5) "Point" }
If I wanted to assign each array to a variable.. say $y and $z.. how would I go about doing it?
I'd like to give you a code example, but I'm not following this completely, so I can't produce tested code. It looks like you have an object instance of stdClass that contains some properties, probably including parts of a geocode. A geocode is a latitude/longitude pair, always expressed in that order, as a pair of signed decimal numbers separated by a comma.
I am guessing that this might be what you want to use (assuming that this describes a location in Rio de Janeiro).
$lat = (string)$obj->coordinates[ 0];
$lon = (string)$obj->coordinates[ 1];
Try that and see if it makes sense.
I am guessing that this might be what you want to use (assuming that this describes a location in Rio de Janeiro).
$lat = (string)$obj->coordinates[
$lon = (string)$obj->coordinates[
Try that and see if it makes sense.
ASKER
It does make sense but it's not working.
The code i entered into the loop is this:
var_dump($j) ;
$lat = (string)$obj->coordinates[ 0];
$lon = (string)$obj->coordinates[ 1];
ECHO '<br> here: '.$lat. '<br>';
what I'm getting when running is:
object(stdClass)#8 (2) { ["coordinates"]=> array(2) { [0]=> float(36.973798) [1]=> float(35.310664) } ["type"]=> string(5) "Point" }
here:
object(stdClass)#11 (2) { ["coordinates"]=> array(2) { [0]=> float(35.243236) [1]=> float(136.985178) } ["type"]=> string(5) "Point" }
here:
So, $lat is not retrieving the array data correctly.
The code i entered into the loop is this:
var_dump($j) ;
$lat = (string)$obj->coordinates[
$lon = (string)$obj->coordinates[
ECHO '<br> here: '.$lat. '<br>';
what I'm getting when running is:
object(stdClass)#8 (2) { ["coordinates"]=> array(2) { [0]=> float(36.973798) [1]=> float(35.310664) } ["type"]=> string(5) "Point" }
here:
object(stdClass)#11 (2) { ["coordinates"]=> array(2) { [0]=> float(35.243236) [1]=> float(136.985178) } ["type"]=> string(5) "Point" }
here:
So, $lat is not retrieving the array data correctly.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was exactly what I was looking for.
Thanks for the points and thanks for using EE - it's a great question ~Ray
http://us1.php.net/manual/en/function.isset.php
http://us1.php.net/manual/en/function.is-null.php
I would recommend using var_dump($decode->results[