Getting tweets from a place using latitude & longitude

Getting tweets from a place using latitude & longitude


Posted in : Java Posted on : October 22, 2011 at 4:34 PM Comments : [ 0 ]

In this section, you will learn how to get the tweets from a specified place.

Getting tweets from a place using latitude & longitude

In this section, you will learn how to get the tweets from a specified place.

For getting tweets from a specified place, you need to put latitude and longitude of a specific place in the function GeoLocation. In the below example, we are going to fetch the tweets from the Nagpur(Maharashtra, India) by passing its latitude in the GeoLocation  function.

For searching tweet you need only one jar file. i.e. twitter4j-core-2.2.5-SNAPSHOT.jar.

Given below the code :

CODE

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="twitter4j.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
//Getting tweets near nagpur
out.println("Getting tweet near nagpur...");
GeoLocation geo = new GeoLocation(20.545024, 79.980469);
Query query1 = new Query().geoCode(geo, 40, "mi");
Twitter twitter = new TwitterFactory().getInstance();
QueryResult result1 = twitter.search(query1);
int i = 1;
for (Tweet tweet3 : result1.getTweets()) {
out.println("<img src='" + tweet3.getProfileImageUrl() + "'>"
+ "<b>(" + i + ") " + tweet3.getFromUser() + "("
+ tweet3.getCreatedAt() + ")" + "</b>" + " : "
+ tweet3.getText() + "<br/>");
i++;
}
%>
</body>
</html>

OUTPUT

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics