List of usage examples for twitter4j Twitter searchPlaces
ResponseList<Place> searchPlaces(GeoQuery query) throws TwitterException;
From source file:geo.SearchPlaces.java
License:Apache License
/** * Usage: java twitter4j.examples.geo.SearchPlaces [ip address] or [latitude] [longitude] * * @param args message//from w w w .j ava 2s. c om */ public static void main(String[] args) { if (args.length < 1) { System.out.println( "Usage: java twitter4j.examples.geo.SearchPlaces [ip address] or [latitude] [longitude]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); GeoQuery query; if (args.length == 2) { query = new GeoQuery(new GeoLocation(Double.parseDouble(args[0]), Double.parseDouble(args[1]))); } else { query = new GeoQuery(args[0]); } ResponseList<Place> places = twitter.searchPlaces(query); if (places.size() == 0) { System.out.println("No location associated with the specified IP address or lat/lang"); } else { for (Place place : places) { System.out.println("id: " + place.getId() + " name: " + place.getFullName()); Place[] containedWithinArray = place.getContainedWithIn(); if (containedWithinArray != null && containedWithinArray.length != 0) { System.out.println(" contained within:"); for (Place containedWithinPlace : containedWithinArray) { System.out.println(" id: " + containedWithinPlace.getId() + " name: " + containedWithinPlace.getFullName()); } } } } System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to retrieve places: " + te.getMessage()); System.exit(-1); } }
From source file:org.wso2.carbon.connector.twitter.TwitterSearchPlaces.java
License:Open Source License
/** * Performing the searching operation for the given Geo Query criteria. * //w w w . ja v a 2s . c om * @param twitter * @param query * @return * @throws XMLStreamException * @throws TwitterException * @throws JSONException * @throws IOException */ private OMElement performSearch(Twitter twitter, GeoQuery query) throws XMLStreamException, TwitterException, JSONException, IOException { OMElement resultElement = AXIOMUtil.stringToOM("<jsonObject><places/></jsonObject>"); OMElement childElment = resultElement.getFirstElement(); List<Place> results = twitter.searchPlaces(query); if (log.isDebugEnabled()) { log.info("executing executing search" + query); } for (Place place : results) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("{ \"place\" : "); String json = DataObjectFactory.getRawJSON(place); stringBuilder.append(json); stringBuilder.append("} "); OMElement element = super.parseJsonToXml(stringBuilder.toString()); childElment.addChild(element.getFirstOMChild()); } if (results.size() == 0) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("{ \"place\" : {}"); stringBuilder.append("} "); OMElement element = super.parseJsonToXml(stringBuilder.toString()); resultElement.addChild(element); } return resultElement; }