/*
 * Copyright 2007 Yusuke Yamamoto
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package model;

import twitter4j.*;
import com.google.gson.Gson;
import java.util.List;
import java.util.logging.Level;

/**
 * @author Yusuke Yamamoto - yusuke at mac.com
 * @since Twitter4J 2.1.7
 */
public class SearchTweets {
    /**
     * Usage: java twitter4j.examples.search.SearchTweets [query]
     *
     * @param args search query
     */
    public static void main(String[] args){
        returnTrend(41,-92);
    }
    public static Object returnTrend(double latitude,double longitude) {
        if (false) {
            System.out.println("java twitter4j.examples.search.SearchTweets [query]");
            System.exit(-1);
        }
        StringBuilder forreturn=new StringBuilder();
        forreturn.append("{\"trends\":[") ;
        
        Twitter twitter = new TwitterFactory().getInstance();
          Object etc=new Object();
        GeoLocation gl;
        System.out.println(latitude+"   "+longitude);
        gl = new GeoLocation(latitude,longitude);
        try {
            ResponseList<Location> responselist;
            responselist = twitter.getClosestTrends(gl);
            System.out.println(responselist.toString());
            Location value=responselist.get(0);
            //JSONObject loc;
         //  String loc=value.toString().substring(value.toString().indexOf("=")+1,value.toString().indexOf(","));
            
            //loc=gson.fromJson(value,Place).toJson();
                        System.out.println(value.toString());

            int woeid=1;
            woeid=value.getWoeid();
           // woeid=Integer.valueOf(loc);
                        System.out.println("SearchTweet TEsting Console");

            Trends placeTrends = twitter.getPlaceTrends(woeid);
            
            int count=0;
            Gson gson=new Gson();
            System.out.println(etc);
            for(Trend sometrend: placeTrends.getTrends()){
                etc=gson.toJson(sometrend);
                forreturn.append(etc);
                count++;
                if(count>5)break;
                forreturn.append(",");

             //  System.out.println(sometrend);
             //                 System.out.println(etc);

            }
            forreturn.append("]}");
            System.out.println(forreturn);
            
          //  etc=gson.toJson(forreturn);
            

/*
            Query query = new Query("tarkariwali");
          //  GeoQuery query = new GeoQuery(new GeoLocation(Double.parseDouble(args[0]), Double.parseDouble(args[1])));
            QueryResult result;
            int count=0;
            do {
                result = twitter.search(query);
                List<Status> tweets = result.getTweets();
                for (Status tweet : tweets) {
                    System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
                   count++;
                   if(count>=10)break;
                }
                 count++;
                    if(count>=10)break;
            } while ((query = result.nextQuery()) != null);
           // System.exit(0);
            
        }*/ 
        }catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to search tweets: " + te.getMessage());
            System.exit(-1);
        }
                    
return forreturn;
    }
    
}

@@ -1,955 +1,158 @@
-/*%0A * Copyright 2007 Yusuke Yamamoto%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage model;%0A%0Aimport twitter4j.*;%0Aimport com.google.gson.Gson;%0Aimport java.util.List;%0Aimport java.util.logging.Level;%0A%0A/**%0A * @author Yusuke Yamamoto - yusuke at mac.com%0A * @since Twitter4J 2.1.7%0A */%0Apublic class SearchTweets %7B%0A    /**%0A     * Usage: java twitter4j.examples.search.SearchTweets %5Bquery%5D%0A     *%0A     * @param args search query%0A     */
+%0Apackage model;%0A%0Aimport twitter4j.*;%0Aimport com.google.gson.Gson;%0Aimport java.util.List;%0Aimport java.util.logging.Level;%0A%0A%0Apublic class SearchTweets %7B%0A   
 %0A   
@@ -1007,222 +1007,8 @@
 0);%0A
-            //JSONObject loc;%0A         //  String loc=value.toString().substring(value.toString().indexOf(%22=%22)+1,value.toString().indexOf(%22,%22));%0A            %0A            //loc=gson.fromJson(value,Place).toJson();%0A 
     
@@ -1138,41 +1138,8 @@
     
-   // woeid=Integer.valueOf(loc);
 %0A   
@@ -1636,106 +1636,8 @@
     
-      //  System.out.println(sometrend);%0A             //                 System.out.println(etc);%0A
 %0A   
@@ -1753,826 +1753,8 @@
     
-//  etc=gson.toJson(forreturn);%0A            %0A%0A/*%0A            Query query = new Query(%22tarkariwali%22);%0A          //  GeoQuery query = new GeoQuery(new GeoLocation(Double.parseDouble(args%5B0%5D), Double.parseDouble(args%5B1%5D)));%0A            QueryResult result;%0A            int count=0;%0A            do %7B%0A                result = twitter.search(query);%0A                List%3CStatus%3E tweets = result.getTweets();%0A                for (Status tweet : tweets) %7B%0A                    System.out.println(%22@%22 + tweet.getUser().getScreenName() + %22 - %22 + tweet.getText());%0A                   count++;%0A                   if(count%3E=10)break;%0A                %7D%0A                 count++;%0A                    if(count%3E=10)break;%0A            %7D while ((query = result.nextQuery()) != null);%0A           // System.exit(0);%0A            %0A        %7D*/ 
 %0A   

Update SearchTweets.java