Search around a given location with Algolia on Android - android

I am developing a navigation application which uses Google Maps. I am trying to implement "my nearby user location" with the application.
I want to use the Algolia service for searching geo-locations using GeoFire with Android & Firebase.
I have successfully stored latitude and longitude information in my Algolia index with their documentation's guidance.
But I don't understand how I can automatically fetch the list and map the location (like in sample project of algolia instant search) based on my current location without entering the place name or any address. Here's my current code:
com.algolia.search.saas.Query query = new com.algolia.search.saas.Query().setAroundLatLng(new com.algolia.search.saas.Query.LatLng(lat,lng)).setAroundRadius(5000);
index.searchAsync(query, new CompletionHandler() {
#Override
public void requestCompleted(JSONObject jsonObject, AlgoliaException e) {
}
});

What's the problem you are facing? Are you blocked on what to do next? The jsonObject you get in requestCompleted is going to be something like:
{
"hits": [
{
"firstname": "Jimmie",
"lastname": "Barninger",
"objectID": "433",
"_highlightResult": {
"firstname": {
"value": "<em>Jimmie</em>",
"matchLevel": "partial"
},
"lastname": {
"value": "Barninger",
"matchLevel": "none"
},
"company": {
"value": "California <em>Paint</em> & Wlpaper Str",
"matchLevel": "partial"
}
}
}
],
"page": 0,
"nbHits": 1,
"nbPages": 1,
"hitsPerPage": 20,
"processingTimeMS": 1,
"query": "jimmie paint"
}
In Java you can access it like jsonObject.getObject("hits").
Are you using instantsearch-android or algoliasearch-client-android ? You should use the instantsearch-android one, is easier to link the search with your UI. Here's an example with GoogleMaps.

Related

How to filter [tag:ChatDialog] messages by custom value in Quickblox?

I am using Quickblox in my application, the problem is when trying to get chatdialog messages filtered with custom value parameter the filter not working.
chat documentation
here is mu code:
ArrayList<QBChatMessage> messages = null;
QBMessageGetBuilder qbMessageGetBuilder = new QBMessageGetBuilder();
qbMessageGetBuilder.eq("bookID", customDialog.getBookID());
qbMessageGetBuilder.sortAsc("date_sent");
try {
messages = QBRestChatService.getDialogMessages(qbChatDialog, qbMessageGetBuilder).perform();
} catch (QBResponseException e) {
e.printStackTrace();
}
response example:
{
"skip": 0,
"limit": 100,
"items": [
{
"_id": "58f6c9f4a28f9a0c7f000003",
"attachments": [],
"bookID": "-Kh9UzvClNyHuwNhLcFV",
"chat_dialog_id": "58f6bcdea0eb4766d900003c",
"created_at": "2017-04-19T02:22:44Z",
//other fields
},
{
"_id": "58f6ca12a28f9a08c5000001",
"attachments": [],
"bookID": "-KeA1pw5DGMSTg67Pbp0",
"chat_dialog_id": "58f6bcdea0eb4766d900003c",
"created_at": "2017-04-19T02:23:15Z",
//other fields
}
]
}
[Update]
I am using 3.3.0 version.
[UPDATE] 22/4/2017
I tried also #Jagapathi answer, I replaced this line
qbMessageGetBuilder.eq("bookID", customDialog.getBookID());
with this:
qbMessageGetBuilder.addRule("bookID", QueryRule.EQ, customDialog.getBookID());
but also doesn't work.
qbMessageGetBuilder.eq
"eq" is not available as per doc for comparing same values for sorting you need to use.
messageGetBuilder.addRule("bookID", QueryRule.EQ, "-Kh9UzvClNyHuwNhLcFV");

Getting and playing 30 second previews from Spotify

I've looked into how to play 30 second previews but so far all I can find is android wrappers for the web API that require user authentication.
I need to be able to search for an artist and play the first preview that pops up without needing the user to authenticate their accounts
You should check: https://developer.spotify.com/web-api/code-examples/
"Search for an Artist (and Lookup) Demo"
It's an example for a web snippet, but you could try to see how it does the connection without needing the user authentication.
If you look at spotify api webpage they mention Endpoints marked “OAuth” above require application registration and user authorization via the Spotify Accounts Service to access certain data.
So in order to get this working i had to chain 2 API calls together. The first one searches for the artist and then the second one looks for the preview:
You call the API with this link (GET):
https://api.spotify.com/v1/search?q=<artist name>&type=artist
which then returns a json structure like this:
{
"artists": {
"href": "https://api.spotify.com/v1/search?query=bring+me+the+horizon&offset=0&limit=20&type=artist",
"items": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/1Ffb6ejR6Fe5IamqA5oRUF"
},
"followers": {
"href": null,
"total": 1067846
},
"genres": [
"metalcore"
],
"href": "https://api.spotify.com/v1/artists/1Ffb6ejR6Fe5IamqA5oRUF",
"id": "1Ffb6ejR6Fe5IamqA5oRUF",
"images": [
{
"height": 640,
"url": "https://i.scdn.co/image/49aad7da4f872acb3005727392631dab282423d1",
"width": 640
},
{
"height": 320,
"url": "https://i.scdn.co/image/d9cf89b9db73b95ed15d9e29e30d0dd8afea23e2",
"width": 320
},
{
"height": 160,
"url": "https://i.scdn.co/image/d9e514e15f4940c77029ef3b11291d557b345ae9",
"width": 160
}
],
"name": "Bring Me The Horizon",
"popularity": 76,
"type": "artist",
"uri": "spotify:artist:1Ffb6ejR6Fe5IamqA5oRUF"
}
],
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total": 1
}
}
Because this then returns the Artist ID we can get the top tracks for that artist and play a preview:
Call the API with this URL (GET):
https://api.spotify.com/v1/artists/<ARTIST ID>/top-tracks?country=GB
From here we can then extract the URL of the preview and play it, all without authentication!

what is the equivalent to newsoft json in android

i have problems i am searching and cant understand what type of json parser i can use for example i have local json and i want to prase it is there any sdk i can use near the newsoft json or ez to learn because i am windows phone and 8.1 developer and i sucks with android and i really need it for graduation project i created almost every thing
[
{
"id": 1,
"time": 40,
"srcLong": 35.909124,
"srcLat": 31.973628,
"destLong": 35.898258,
"destLat": 31.985622,
"subSites": [
{
"id": 1,
"name": "location 1"
},
{
"id": 2,
"name": "location 2"
},
{
"id": 3,
"name": "location 3"
}
]
}]
plz how to get the response for example the code in newsoft json is like this
var serviceUri = "http://localhost:24728/api/sites";
HttpClient client = new HttpClient();
var response = await client.GetAsync(serviceUri);
var datafile = await response.Content.ReadAsStringAsync();
RootObject data = JsonConvert.DeserializeObject<RootObject (((string)datafile).Substring(1, ((string)datafile).Length - 2));
and of course you create the class to deal with object plz can some one help me with this and i need to remove the [] to be json object i just need the sdk i should use and where to start learn and if there no problem to tell me how to substring it and to put this code
string uri = "http://localhost:24728/api/sites/1";
HttpResponseMessage response2 = await client.PutAsJsonAsync(uri, data);
plz is there any equivalent in android.
Regards,
Ayesh.
Well from what you are saying it looks like you are unsure of how to get a response from the site, maybe you do not understand how to access the url initially. Or potentially that once you get the response and it is prehaps a string you do not know how to convert it into JSON to extract the information. Send information from android application to a Web Service and back. This link has a basic version of connecting to a url. And when you have a string, you can use JSONObject and JSONArrays to grab the information on that string, you can do JSONArray(string).

error page occurs while accessing buy link of Google books API result

i am doing a bar code scanner application.I am trying to get Google book details from the bar code ISBN number in android application. Also i got all the book details from API result successfully. But if i try to access the buy link from API result, i am unable to access the buy link of the book. It says 404 error. Can anyone help me, how to access the buy link to buy a book.? Thanks in advance.
Here is the buy link of book got from below result:
http://books.google.co.in/books?id=xqxBtXmxqV4C&dq=isbn:9781849699327&hl=&buy=&source=gbs_api
Here is the API result:
"saleInfo": {
"country": "IN",
"saleability": "FOR_SALE",
"isEbook": true,
"listPrice": {
"amount": 162.0,
"currencyCode": "INR"
},
"retailPrice": {
"amount": 113.4,
"currencyCode": "INR"
},
"buyLink": "http://books.google.co.in/books?id=xqxBtXmxqV4C&dq=isbn:9781849699327&hl=&buy=&source=gbs_api",
"offers": [
{
"finskyOfferType": 1,
"listPrice": {
"amountInMicros": 1.62E8,
"currencyCode": "INR"
},
"retailPrice": {
"amountInMicros": 1.134E8,
"currencyCode": "INR"
}
}
]

Facebook social plugin on android

I would like to integrate Facebook's comment social plugin
( https://developers.facebook.com/docs/reference/plugins/comments/ to comment on url) into my android application.
I tried to use webview (use this answer Android unable to implement facebook comment in a webview due to default browser ) and it's work, but hard to customize, for example: I want to have a bigger Textbox for user to type the comment. My question is: "is there any solution to integrate something like "Facebook's comment social plugin" into android application by facebook sdk, java code,... to comment on url?
Thanks & best regards
As far as I understand you have some URL page where you've embedded your facebook social plugin with comments and you want to parse this and display as you want. If I'm right, then unfortunately I haven't found easy solution via triggering appropriated methods from Facebook SDK. You have to use Graph API.
First of all we need to take a look into docs - https://developers.facebook.com/docs/graph-api/reference/v2.3/object/comments
Here there is a example of call
/* make the API call */
new Request(
session,
"/{object-id}/comments",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
For getting {object_id} you need to send similar call to the Graph API, but for retrieving id:
GET-> ?id=http%3A%2F%2Fwww.imdb.com%2Ftitle%2Ftt2015381%2F
And you will receive response which looks like
{
"og_object": {
"id": "10150298925420108",
"description": "Directed by James Gunn. With Chris Pratt, Vin Diesel, Bradley Cooper, Zoe Saldana. A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.",
"title": "Guardians of the Galaxy (2014)",
"type": "video.movie",
"updated_time": "2015-05-15T14:52:46+0000",
"url": "http://www.imdb.com/title/tt2015381/"
},
"share": {
"comment_count": 4,
"share_count": 91073
},
"id": "http://www.imdb.com/title/tt2015381/"
}
10150298925420108 is our object_id
So next query looks like GET -> 10150298925420108/comments
and response
{
"data": [
{
"id": "10150298925420108_10152457293990108",
"can_remove": false,
"created_time": "2014-10-28T18:12:15+0000",
"from": {
"id": "1513986108857171",
"name": "ซอโซ่ สระอา ยอยัก"
},
"like_count": 2,
"message": "สนุกมากค่ะ",
"user_likes": false
},
{
"id": "10150298925420108_10152457392770108",
"can_remove": false,
"created_time": "2014-10-28T19:20:28+0000",
"from": {
"id": "302917246580502",
"name": "สมชาย โกทันธ์"
},
"like_count": 0,
"message": "สองดาวครับ\n",
"user_likes": false
},
{
"id": "10150298925420108_10152461977130108",
"can_remove": false,
"created_time": "2014-10-31T11:57:10+0000",
"from": {
"id": "472810482857795",
"name": "Surat Thaenphet"
},
"like_count": 0,
"message": "แต่ละเรื่องที่ลง สนุกมาก แต่ดูไม่จบ ดูสักพัก ก็ eror ไม่รุ้เป็นเพราะอะไร",
"user_likes": false
}
],
"paging": {
"cursors": {
"before": "Mw==",
"after": "MQ=="
}
}
}
To test all this requests and response before doing it in Android app - use Graph API explorer https://developers.facebook.com/tools/explorer/

Categories

Resources