GET search/tweets - Looking to get lat & longs


#1

Hi just looking to see if anyone can help out.

I’m new to developing and this is my first Twitter app. I am learning lots as I am trying to develop this app, but I am abit stumped and have ran into a problem that I can’t find a answer.

This being getting lat & long from a hashtag search. - I know the user needs to have this enabled, but I trying to get the data for users that do.

What I have done so far;

Connected to Twitter API
Got my search hashtag working and data coming through, however the data only includes location and not lat & long.

What I need to do.

Find a way to get lat long data from the tweets on the hashtag.

$url = "https://api.twitter.com/1.1/search/tweets.json";
$requestMethod = "GET";
$getfield = '?q='.$search.'&result_type=recent&count=1';
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest();

This is what I have so far, the data isn’t decoded (I want to get the correct data first) once recieved but can be viewed and understood a little bit.


#2

First I would maybe not use &count=1, as the chance drops that the returned Tweet will contain a Location. The returned Tweet will contain a coordinates field, if there is a location attached to it.
The coordinates value consists of an array in the form: [longitude, latitude].
For example: { … "coordinates":[-97.51087576,35.46500176] … }

For more information what kind of Information a Tweet Object contains, please refer to the Tweet Documentation Page. This explains very detailed each field of a Tweet and what it means, additionally for most fields there are example values provided.


#3

Solved thanks!