Suzanne Jacobs
Suzanne Jacobs

Reputation: 28

Get latitude, longitude from restfb

I used to use fql to get latitude and longitude from Place.

How do I do it nowadays? I've got the user's location, but only id and name are filled in. Everything else is null. Code:

FacebookClient fc = new DefaultFacebookClient(token, Version.VERSION_2_9);
User user = fc.fetchObject("me", User.class, Parameter.with("location"));
Location loc = fc.fetchObject(user.getLocation().getId(), Location.class);

Also tried:

Place pl = fc.fetchObject(user.getLocation().getId(), Place.class);

Same thing.

Upvotes: 0

Views: 48

Answers (1)

Norbert
Norbert

Reputation: 1462

As I wrote in the RestFB bugtracker:

FacebookClient fc = new DefaultFacebookClient(token, Version.VERSION_2_9);
User user = fc.fetchObject("me", User.class, Parameter.with("fields","location"));
Page pageOfUserLocation = fc.fetchObject(user.getLocation().getId(), 
Page.class, Parameter.with("fields","location");
if (pageOfUserLocation.getLocation() != null) {
  System.out.println("longitude: ", pageOfUserLocation.getLocation().getLongitude());
  System.out.println("latitude: ", pageOfUserLocation.getLocation().getLatitude());
}

Upvotes: 1

Related Questions