I am using spring social Facebook to connect to facebook. The connection works well. I am trying to get the user's location with the following code:
FacebookProfile profile = facebook.userOperations().getUserProfile();
Reference rLocation = profile.getLocation();
Location location= facebook.fetchObject(rLocation.getId(), Location.class);
But what I get is an empty location object (it doesn't have any of the details). I can see that the rLocation does have a name (Los Angeles) but I also need the country.
Any idea how to get the actual Location object?
You can only get the location details that are a part of the Reference object which is the rLocation here. You can get the location city and location state but the location country is not a part of the Reference object.
Reference rLocation = profile.getLocation();
String locationName = rLocation.getName();
String[] cityAndState = locationName.split(",");
String city = cityAndState[0].trim();
String state = cityAndState[1].trim();
The Location object basically helps to get the details of a user checked in location in facebook. Please refer to the spring social facebook API for more details.
http://static.springsource.org/spring-social-facebook/docs/1.0.x/api/org/springframework/social/facebook/api/Location.html
Related
I want to create an application that tracks childs location through firebase and implement geofence on that location. How do i initiate GeofenceClient with that location from firebase instead of my own location?
I have created an app that is fetching location from database of other user which is in latitude and logitude and can be converted to latlng datatype. I have also created feature of geofencing but heres the problem : This geofence check my location for geofence(i suppose this is happening because i have intiated geofence Client as //geofencingClient = LocationServices.getGeofencingClient(this);)
What should i do to pass the location of other user that i fetched from firebase in form of latitude and longitude in this geofencingClient.
I am developing an android app and I am trying to check if the user's current location is the same with one of some addresses that I hold in a csv.
For example:
An address from the csv is a String like "Via dei Monti Tiburtini 385, Roma 00157 "
At first I have get the fully current location by the following code
Geocoder geocoder;
List<Address> addresses = null;
geocoder = new Geocoder(MainActivity.this, locale);
try {
addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
} catch (IOException e) {
e.printStackTrace();
}
String address = addresses.get(0).getAddressLine(0);
I thought to make just check if the Strings are equals but ofcourse this is not a right solution because the location addresses can differ in the way that been written.
For example:
csv file -> "Via dei Monti Tiburtini 385, Roma 00157 "
user's current loc -> "Via dei Monti Tiburtini 385, Roma 00157, ITALY "
Note: My addresses are not in english characters (both user's current loc and csv loc) but for now I would like to find a solution at least for english
I am trying to find something on the web but I am not able to find something similar to that.
I would appreciate any help, Thank you
Checking if GPS coordinates are equal might be too restrictive, I agree with you. What you could do is check if they are within a certain range, maybe 0.01% margin from what's in your DB. You can test it on Google Maps and see how much you think you can tolerate based on your application.
This page has some details about the numerical values for latitude and longitude:
https://en.wikipedia.org/wiki/Geographic_coordinate_system
From a user address perspective, in my experience with shipping applications, there is this concept of Address Standardization which tries to make the addresses conform in format so that other systems consistently find the same location.
This could help with how people enter their address for example "apartment #3" or "app #3" or "app 3", which could all result in different addresses. There are libraries for UPS and others that provide this.
https://www.ups.com/us/en/services/shipping/connectship.page
This is if you are starting from an address.
If you start from GPS location, you could use API-s available on the web, maybe Google Maps, to find the address of a specific GPS location.
https://www.google.com/maps/#44.4257258,-88.1063132
and this:
https://support.google.com/maps/answer/18539?hl=en&co=GENIE.Platform%3DDesktop
I am testing google map for localization testing. I have to set location of except from my current location. But it is taking my current location.
Sample Code:
Location location = new Location(77.59974003, 12.91024781, 909);
driver.setLocation(location);
Try using the code which you have written for seting the location before the map is displayed.
Location location = new Location(77.59974003, 12.91024781, 909);
driver.setLocation(location);
This will set the driver location before the map is displayed on the screen.
I'm trying to get user location in Spring Social Facebook:
Facebook fb = ((Facebook) connection.getApi());
Page pg = fb.pageOperations().getPage(fb.userOperations().getUserProfile().getLocation().getId());
The problem is that pg.getLocation() returns null.
I also tried with
fb.fetchObject(fb.userOperations().getUserProfile().getLocation().getId(), org.springframework.social.facebook.api.Location.class)
but it does populate only the name, not country or other fields.
Trying on Graph API Explorer /v2.6/112286918797929?fields=id,name,location returns as expected:
{
"id": "112286918797929",
"name": "Sacele",
"location": {
"city": "Sacele",
"country": "Romania",
"latitude": 45.6167,
"longitude": 25.6833
}
}
Is this an issue with Spring Social Facebook?
I'm using Spring Social 1.1.4 and Spring Social Facebook 2.0.3.
I also tried Spring Social for Facebook - get user location, but unfortunately not all the places follow the name convention City, Country and some of them include in the name only the city, not the country too. Plus how can you get the geo-coordinates?
I finally got it. First of all it doesn't work with PageOperations, but it works with GraphApi.
And the code is
UserProfile userProfile = fb.userOperations().getUserProfile();
Page pg = fb.fetchObject(userProfile.getLocation().getId(), Page.class, "location");
The trick is specifying the third parameter, which represents the fields (you can specify multiple fields as strings). Now the page is populated and you can get the country like pg.getLocation().getCountry().
As you stated that, the following command
fb.fetchObject(fb.userOperations().getUserProfile().getLocation().getId(), org.springframework.social.facebook.api.Location.class)
gives response the name which is from Reference.
That's have 2 public methods: getId() and getName().
Some methods like getLocation() is depends on permission. If any user gives you permission to see his location, then you can access this method.
From documentation:
getLocation
public Reference getLocation()
The user's location. Available only with "user_location" or "friends_location" permission.
Returns: a
Reference to the user's location, if available
Code Sample:
Page profile=facebookTemplate.pageOperations().getPage(id);
String name=profile.getName();
String webside=profile.getWebsite();
String logo="http://graph.facebook.com/" + id + "/picture";
party=new FullPoliticalParty(name,color,logo,webside);
String phone=profile.getPhone() == null ? "No disponible" : profile.getPhone();
party.setPhone(phone);
org.springframework.social.facebook.api.Location loc=profile.getLocation();
if (loc != null) {
location=new LocationMapa(loc.getCity(),loc.getCountry(),loc.getStreet(),loc.getZip());
}
party.setLocation(location);
Resource Link:
Location class
Java Code Examples for
org.springframework.social.facebook.api.Page
UPDATE1:
I think you need user permissions through Graph API. Then you can access location or other info that you requested from specific user. Checking Current Permissions and Handling Missing Permissions is given in this link.
For USER permissions:
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{user-id}/permissions",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
For user permissions, you can go through this tutorial
For user location, you can go through this tutorial.
After getting related permission, you can get access location, longitude, latitude and other info also.
I went through the API documentation for /media/recent, but it does not specify what is the duration for which we receive the media files for a specific location.
They have mentioned that we could pass the below parameters to the API.
MIN_TIMESTAMP
MAX_TIMESTAMP
Can anyone give me an example on how to pass this value to the API?
Also is there any API exposed to get the total number of photos for a specific location in instagram?
you can use the medis.search endpoint:
http://instagram.com/developer/endpoints/media/#get_media_search
you have to pass lat and lng for location, max_timestamp and min_timestamp are option and can be specified in epoch time.
here is example:
https://api.instagram.com/v1/media/search?max_timestamp=1410332400&distance=1000&lat=37.8062&lng=-122.4738&access_token=XXX
Here is an implementation using this API, you can search by location and filter by date:
http://www.gramfeed.com/instagram/map