Example usage for twitter4j Place getContainedWithIn

List of usage examples for twitter4j Place getContainedWithIn

Introduction

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

Prototype

Place[] getContainedWithIn();

Source Link

Usage

From source file:DataCollections.PlaceHelper.java

public Place_dbo convertPlacetoPlace_dbo(Place place) {
    Place_dbo placedbo = new Place_dbo();
    placedbo.values[Place_dbo.map.get("place_id")].setValue(place.getId());
    placedbo.values[Place_dbo.map.get("name")].setValue(place.getName());
    placedbo.values[Place_dbo.map.get("full_name")].setValue(place.getFullName());
    placedbo.values[Place_dbo.map.get("country")].setValue(place.getCountry());
    placedbo.values[Place_dbo.map.get("country_code")].setValue(place.getCountryCode());
    placedbo.values[Place_dbo.map.get("place_type")].setValue(place.getPlaceType());
    placedbo.values[Place_dbo.map.get("url")].setValue(place.getURL());
    placedbo.values[Place_dbo.map.get("contained_within_place")]
            .setValue(getAllContainedWithIngPlaces(place.getContainedWithIn()));
    placedbo.values[Place_dbo.map.get("boundingbox_coord")]
            .setValue(stringifyBoundingBoxCoordinates(place.getBoundingBoxCoordinates()));
    double[] centroid = computeCentroid(place.getBoundingBoxCoordinates());
    placedbo.values[Place_dbo.map.get("centroid_lon")].setValue(String.valueOf(centroid[0]));
    placedbo.values[Place_dbo.map.get("centroid_lat")].setValue(String.valueOf(centroid[1]));

    return placedbo;
}

From source file:geo.GetGeoDetails.java

License:Apache License

/**
 * Usage: java twitter4j.examples.geo.GetGeoDetails [place id]
 *
 * @param args message/*  ww w .ja v  a  2s.co  m*/
 */
public static void main(String[] args) {
    String s = "939067979a7f3b95";
    try {
        Twitter twitter = new TwitterFactory(Data.getConf().build()).getInstance();
        Place place = twitter.getGeoDetails(s);
        System.out.println("name: " + place.getName());
        System.out.println("country: " + place.getCountry());
        System.out.println("country code: " + place.getCountryCode());
        System.out.println("full name: " + place.getFullName());
        System.out.println("id: " + place.getId());
        System.out.println("place type: " + place.getPlaceType());
        System.out.println("street address: " + place.getStreetAddress());

        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 geo details: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:geo.GetSimilarPlaces.java

License:Apache License

/**
 * Usage: java twitter4j.examples.geo.GetSimilarPlaces [latitude] [longitude] [place id]
 *
 * @param args message//from  ww  w.  j  av a 2  s .  c  om
 */
public static void main(String[] args) {
    if (args.length < 3) {
        System.out.println(
                "Usage: java twitter4j.examples.geo.GetSimilarPlaces [latitude] [longitude] [name] [place id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        GeoLocation location = new GeoLocation(Double.parseDouble(args[0]), Double.parseDouble(args[1]));
        String name = args[2];
        String containedWithin = null;
        if (args.length >= 4) {
            containedWithin = args[3];
        }
        ResponseList<Place> places = twitter.getSimilarPlaces(location, name, containedWithin, null);
        if (places.size() == 0) {
            System.out.println("No location associated with the specified condition");
        } else {
            for (Place place : places) {
                System.out.println("id: " + place.getId() + " name: " + place.getFullName() + " 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 find similar places: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:geo.ReverseGeoCode.java

License:Apache License

/**
 * Usage: java twitter4j.examples.geo.ReverseGeoCode [latitude] [longitude]
 *
 * @param args message//from   w ww  .  ja  va2s  .co  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  www. j  av a2s  . c o  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:twitter4j.examples.geo.GetGeoDetails.java

License:Apache License

/**
 * Usage: java twitter4j.examples.geo.GetGeoDetails [place id]
 *
 * @param args message/*from  w ww. j  a  v  a  2 s  .c o  m*/
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.geo.GetGeoDetails [place id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        Place place = twitter.getGeoDetails(args[0]);
        System.out.println("name: " + place.getName());
        System.out.println("country: " + place.getCountry());
        System.out.println("country code: " + place.getCountryCode());
        System.out.println("full name: " + place.getFullName());
        System.out.println("id: " + place.getId());
        System.out.println("place type: " + place.getPlaceType());
        System.out.println("street address: " + place.getStreetAddress());
        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 geo details: " + te.getMessage());
        System.exit(-1);
    }
}