I am using OkHTTP to simply get text from the body of a url:
class DownloadUrl {
String readUrl(String myUrl) throws IOException,NullPointerException {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(myUrl)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
}
However, I am getting inconsistent String, despite the URL and its contents being same every time. The some returned string leave out blocks of the JSON for example, I should be getting this:
"html_attributions" : [],
"results" : [
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png",
"id" : "b89943f74e20eafb8959ace996a6f35cd303d5ff",
"name" : "Circle K",
"opening_hours" : {
"open_now" : true,
"weekday_text" : []
},
"photos" : [
{
"height" : 400,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/114668422179892290420/photos\"\u003eCircle K\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAAdubSCt5u9IrI6bsL91DGLdIm2SMO39SaKGxKKmrj-ygxrCmIjUzG0DwrBgcX56DdpEFRBev29cdA4ljZnIR7lvPlP3jBhHkBxliRkGlAlfkAh9TiQvVuyNNQLnzIcsuEhAsc0Px0hV4mFTZruHRWLh9GhTIePuzk5JxV1QewH3jimkAKIzALw",
"width" : 400
}
],
Instead, I'm getting:
"html_attributions" : [],
"results" : [
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "1a830f99aab4e7afa143b2c8d03545ea7c1e9432",
"name" : "McDonald's",
"opening_hours" : {
"open_now" : true,
"weekday_text" : []
},
The "photos" part of the JSON is being left on some calls, any ideas? Thanks.
According to Google Place Search documentation (which is the service you're using, I guess), each result object may contain:
photos[] — an array of photo objects, each containing a reference to an image. A Place Search will return at most one photo object.
Also, Google Place Photos documentation reports that:
The response [...] will contain a photos[] field if the place has related photographic content.
That means that in case a specific result has no photos, then photos array won't be present at all in the response.
The examples you provided are not referring to the same place: in the first case you're getting a result for "Circle K", while in the second case for "McDonald's". Based on that, the response seems coherent with what the documentation says.
Related
I've got the following json response from spotify api:
{
"artists" : {
"href" : "https://api.spotify.com/v1/search?query=U2&type=artist&offset=0&limit=20",
"items" : [ {
"external_urls" : {
"spotify" : "https://open.spotify.com/artist/51Blml2LZPmy7TTiAg47vQ"
},
"followers" : {
"href" : null,
"total" : 3146466
},
"genres" : [ "irish rock", "permanent wave", "rock" ],
"href" : "https://api.spotify.com/v1/artists/51Blml2LZPmy7TTiAg47vQ",
"id" : "51Blml2LZPmy7TTiAg47vQ",
"images" : [ {
"height" : 640,
"url" : "https://i.scdn.co/image/e22d5c0c8139b8439440a69854ed66efae91112d",
"width" : 640
}, {
"height" : 160,
"url" : "https://i.scdn.co/image/7293d6752ae8a64e34adee5086858e408185b534",
"width" : 160
} ],
"name" : "U2",
"popularity" : 76,
"type" : "artist",
"uri" : "
I would like to get the id value, which in this case is
51Blml2LZPmy7TTiAg47vQ
but I can't figure out how to make a query in this json using dart.
I tried out as this answer but did not work.
Is there any way to make a query on json with flutter?
Try json.decode(string)['artists']['items'][0]['id']
json.decode decodes the string to a Map<dynamic, dynamic> containing nested Maps and Lists into which you can index. (Maps are indexed by key; Lists are indexed by integer.)
So I have the Json in following format on firebase:
{
"30000000549656652" : {
"cast" : [ {
"src" : "https://encrypted-tbn1.gstatic.com/images",
"title" : "Hilary Duff (Samantha \"Sam\" Montgomery)"
}],
"channel_name" : "HBO",
"desc" : "After her .....",
"extras" : {
"initial" : "July 10, 2004 (Hollywood)",
"director" : "Mark Rosman",
"screenplay" : "Leigh Dunlap"
},
"genre" : "Thriller",
"lang" : "English",
"movie" : 1,
"prog_id" : 30000000549656652,
"prog_img" : "http://images."
"ratings" : {
"IMDb" : "5.9/10",
"Metacritic" : "25%",
"Rotten Tomatoes" : "11%"
},
"start" : 201607141800,
"stop" : 201607141700,
"title" : "Thrill A Cinderella Story",
"year" : "2004"
},
.....
}
I want to do the following in activity on my android app-
Query the node in which these JSON exist, then filter them such that i get all the results which have movies of one specific genre(e.g., Thriller) and the year is within five yrs less or five yrs more of the one i would pass in the query.
Like i would want to query to get all thriller movies whose "year" are between 2000 and 2009.
Can someone please help me to build such query for a json like this. Thanks!
I've been using Google place API on old projects, but on those projects I had to pick a place and then, the API returned to me information about that place...
The thing is with this same API can I ask for a place for example Restaurant X, and then I get a json or xml with all of those Restaurant X (nearby or not)?
Or if it's another API to get places without having to pick them manually feel free to say it to me.
EDIT
I've found a tutorial but it's kinda old... but the thing is that I've implement all of those stuff and when I click on any item from the Spinner nothing changes...
And I think I'm calling correct the API
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=41.493375,2.354788333333333&radius=5000&types=restaurant&sensor=true&key=AIzaSyBXxZ6lF5WGqCi4ToRJoFihTxGOVzC5vGE
The Google Places API has a REST end-point that you could use to get back details of places of various types within the vicinity you provided.
For example, this end-point https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=44.661704,%20-63.609050&radius=2000&types=restaurant&name=thai&key=XXXX would return back all 'restaurants' that has a name 'thai' in it as a JSON.
The result would be something like this:
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : 44.6496741,
"lng" : -63.61783519999999
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "00b680706e7d8085d4b010b2d99789d8d046f9aa",
"name" : "Thai Express",
"opening_hours" : {
"open_now" : true,
"weekday_text" : []
},
"photos" : [
{
"height" : 517,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/104629276961555072183/photos\"\u003eThai Express\u003c/a\u003e"
],
"photo_reference" : "CmRdAAAAJktMRG2eiCnmejhFOWMYxdpUq97IpUv407jlwfWGAPVVaksJsk36Cbv6ZONNfGs92kEA1Wtgw_4V_dCz5PhABknBl8eR-XIkloEQF2Cs9XmQbmQmV3lW5Q6hz4DYtPJwEhBuQUr3CwPP4dJmBnBfkLLmGhSB76vOFUm-NA_ab42xrdAPDhoq0A",
"width" : 1562
}
],
"place_id" : "ChIJa6gRMpghWksRHseXPRkQT6c",
"reference" : "CmRgAAAARuvIKASXzP7UxvFCd3dZ8TnIX58O2SHrtySdT09_HjwYFld8ktryg3mEvIyf-utJhnjPxJ74dV1Vk6slCTwdL3NOW4MYpDkyh3v1lCXYG1bdFw-QzchfeFC-KISlRkbWEhD_iDkV6G1ctXxnALq-rlyAGhTHCjz-C9bbQ9eE2NZeX34--ficrA",
"scope" : "GOOGLE",
"types" : [
"meal_takeaway",
"meal_delivery",
"restaurant",
"food",
"point_of_interest",
"establishment"
],
"vicinity" : "7001 Mumford Road, Halifax"
}
],
"status" : "OK"
}
More details about the Places API Web Service are here - https://developers.google.com/places/web-service/intro. The supported types you could search for are here - https://developers.google.com/places/supported_types.
Hope this answers your question.
Is there a way I can get my response to be a single object with an array of users using Eloquent?
For instance:
{
"results" : [
{ "email" : "test1#test.ca" },
{ "email" : "test2#test.ca" }
]
}
Current it outputs like this:
[
{
"email": "test1#test.ca",
},
{
"email": "test2#test.ca",
}
]
This is how I'm displaying users from my code:
$users = User::whereIn('number', $numbers)->select('email')->get();
return $users;
Which would be fine but I'm using Volley for Android using JSONObjectRequest but its failing when it tries to parse the JSON because it can't parse the array.
You can try it like this:
$users = User::whereIn('number', $numbers)->select('email')->get();
return Response::json(array('results' => $users));
I am looking at the Google-Distance matrix here
According to Docs if we provide latitude & longitude values we we be replied back with information back from google
I tested with a sample :: Latitude=12.918494 Longitude=77.669387
http://maps.googleapis.com/maps/api/distancematrix/json?origins=12.918494,77.669387&destinations=12.961323,77.647415&language=tr-TR&sensor=false&option=driving&units=metric
I got a JSON response::
{
"destination_addresses" : [
"28, 4th Cross Road, HAL 3rd Stage, Hal, Puttappa layout, New Thippasandra, Bangalore, Karnataka 560008, Hindistan"
],
"origin_addresses" : [
"14, Sarjapur Main Road, Ambalipura, Harlur, Bangalore, Karnataka 560102, Hindistan"
],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "10,5 km",
"value" : 10544
},
"duration" : {
"text" : "19 dakika",
"value" : 1119
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
What i am trying to achieve::
I want to get the value Bangalore(cityname) from the Json
I could parse the Json and get it but problem is if say we give some
other co-ordinates the address could be longer and seperated by
coma's so i can't predict where the cityname will be
What i am trying to achieve::
Is there a way like a function using which i can get the Bangalore as we do in Geocoder
Note:: I dont wan't to use geocode & i am trying to achieve using this
I am new to android, please go easy with answers
Hope i am clear, Thanks