Example usage for twitter4j GeoQuery GeoQuery

List of usage examples for twitter4j GeoQuery GeoQuery

Introduction

In this page you can find the example usage for twitter4j GeoQuery GeoQuery.

Prototype

public GeoQuery(String ip) 

Source Link

Document

Creates a GeoQuery with the specified IP address

Usage

From source file:com.appspot.bitlyminous.handler.twitter.NearByHandler.java

License:Apache License

@Override
public StatusUpdate execute(Status tweet) {
    GeoLocation geoLocation = tweet.getGeoLocation();
    String text = getMentionText(tweet);
    if (geoLocation == null) {
        StatusUpdate reply = new StatusUpdate(
                ApplicationResources.getLocalizedString("com.appspot.bitlyminous.message.noLocation",
                        new String[] { "@" + tweet.getUser().getScreenName() }));
        reply.setInReplyToStatusId(tweet.getId());
        return reply;
    } else {/*from w  w w  .j  a v  a 2 s .  co m*/
        try {
            GeoQuery query = new GeoQuery(geoLocation);
            List<Tip> nearbyTips = getFoursquareGateway()
                    .getNearbyTips(new com.appspot.bitlyminous.entity.GeoLocation(geoLocation.getLatitude(),
                            geoLocation.getLongitude()), 1);
            String status = buildTipsStatus(nearbyTips);

            if (nearbyTips.isEmpty()) {
                List<Venue> nearbyVenues = new ArrayList<Venue>();
                if (text != null) {
                    nearbyVenues = getFoursquareGateway().getNearbyVenues(
                            new com.appspot.bitlyminous.entity.GeoLocation(geoLocation.getLatitude(),
                                    geoLocation.getLongitude()),
                            text, 1);
                }
                status = status + buildVenuesStatus(nearbyVenues);
                if (nearbyVenues.isEmpty()) {
                    List<Place> nearbyPlaces = getTwitterClient().getNearbyPlaces(query);
                    status = status + buildPlacesStatus(nearbyPlaces);
                }

            }
            status = "@" + tweet.getUser().getScreenName() + " " + status;
            StatusUpdate reply = new StatusUpdate(status);
            reply.setInReplyToStatusId(tweet.getId());
            return reply;
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Error while getting nearby places", e);
        }
        return null;
    }
}

From source file:geo.ReverseGeoCode.java

License:Apache License

/**
 * Usage: java twitter4j.examples.geo.ReverseGeoCode [latitude] [longitude]
 *
 * @param args message//from  ww w  .ja  v  a2 s  .c o  m
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java twitter4j.examples.geo.ReverseGeoCode [latitude] [longitude]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        GeoQuery query = new GeoQuery(
                new GeoLocation(Double.parseDouble(args[0]), Double.parseDouble(args[1])));
        ResponseList<Place> places = twitter.reverseGeoCode(query);
        if (places.size() == 0) {
            System.out.println("No location associated with the specified 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:geo.SearchPlaces.java

License:Apache License

/**
 * Usage: java twitter4j.examples.geo.SearchPlaces [ip address] or [latitude] [longitude]
 *
 * @param args message//from w  ww .j  a  v  a  2s .  co m
 */
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.mule.twitter.TwitterConnector.java

License:Open Source License

private GeoQuery createQuery(Double latitude, Double longitude, String ip) {
    if (ip == null) {
        return new GeoQuery(new GeoLocation(latitude, longitude));
    }//ww w. j  a va  2  s  .  c  o  m
    return new GeoQuery(ip);
}

From source file:org.wso2.carbon.connector.twitter.TwitterSearchPlaces.java

License:Open Source License

@Override
public void connect(MessageContext messageContext) throws ConnectException {
    // TODO Auto-generated method stub
    if (log.isDebugEnabled()) {
        log.info("executing twitter search places");
    }/*from  w  w w .  j a  v a  2s  .  c  om*/
    try {
        String latitude = TwitterUtils.lookupTemplateParamater(messageContext, SEARCH_BY_LATITUDE);
        String longitude = TwitterUtils.lookupTemplateParamater(messageContext, SEARCH_LONGITUDE);
        String ip = TwitterUtils.lookupTemplateParamater(messageContext, SEARCH_IP);
        GeoQuery query = new GeoQuery(
                new GeoLocation(Double.parseDouble(latitude), Double.parseDouble(longitude)));
        Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient();
        OMElement element = this.performSearch(twitter, query);
        if (log.isDebugEnabled()) {
            log.info("executing prparing soap envolope" + element.toString());
        }
        super.preparePayload(messageContext, element);
    } catch (TwitterException te) {
        log.error("Failed to search twitter : " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    } catch (Exception te) {
        log.error("Failed to search generic: " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    }
}