Google Places API Web Service shows photo_reference, but Javascript library doesn't - google-places-api

I'm building a basic places search page and I'm using the Google Places Javascript library for it (text search). I do get one "photo" element back, but I noticed that the "photo_reference" field is empty. Here a sample request:
var service = new google.maps.places.PlacesService(this.map);
service.textSearch({query: 'harbour bridge'}, this.callback.bind(this));
Repsonse:
{
"formatted_address":"Sydney Harbour Bridge, Sydney NSW, Australia",
"geometry":{
"location":{
"lat":-33.8523063,
"lng":151.21078710000006
}
},
"icon":"https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id":"e22913360d0b946d099c7a32a77a95e49f9ead66",
"name":"Sydney Harbour Bridge",
"photos":[{
"height":4000,
"html_attributions":["Jasper Straver"],
"width":6000
}],
"place_id":"ChIJ49XqJV2uEmsRPsTAF7eOlGg",
"rating":4.7,
"reference":"[...]",
"types":["point_of_interest", "establishment"],
"html_attributions":[]
}
If I do the same request using the web service, I get the photo_reference. Example:
https://maps.googleapis.com/maps/api/place/textsearch/json?key=[...]&query=harbour%20bridge
Response:
{
"formatted_address" : "Sydney Harbour Bridge, Sydney NSW, Australia",
"geometry" : {
"location" : {
"lat" : -33.8523063,
"lng" : 151.2107871
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "e22913360d0b946d099c7a32a77a95e49f9ead66",
"name" : "Sydney Harbour Bridge",
"photos" : [
{
"height" : 4000,
"html_attributions" : ["\u003ca href=\"https://maps.google.com/maps/contrib/113178678511744469415/photos\"\u003eJasper Straver\u003c/a\u003e"],
"photo_reference" : "CmRdAAAAY-WUame_CRFnMFmUN4UlvFHI7o3tQOqXJxTkjQINgzMQOOheBzLPIm43dlIAIkhFyugFAw8fnf-ItEiUp1j48B23sCDFRtCWM123euhDif_P1jYkvFAjDrPxq1rCnmi2EhCt6LpVl5W-AKPLRkW_tzs6GhRlG4dx2CVuTNZZMFFo3eYMSFWzGg",
"width" : 6000
}
],
"place_id" : "ChIJ49XqJV2uEmsRPsTAF7eOlGg",
"rating" : 4.7,
"reference" : "[...]",
"types" : [ "point_of_interest", "establishment" ]
}
How come there is a difference between the JS and Web Services API? How can I get the photo_reference from the JS library? (I don't want to make a getDetails(...) request for each search result)
Thanks!

photo_reference is for the Google Places API Web Service. With the Places Javascript library you can just call getUrl on the elements of the photos array, e.g. place.photos[0].getUrl({maxWidth: 1000}).
Like the Web Service, search results won't have more than 1 photo.

Related

How to get original, not translated, name of the place using Google Places API?

I want to get info about some place, let's say I use this link https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJFfz5V9zi20ARwBqCYQXOIVM&fields=vicinity,name&key=MY_API_KEY, I will get this result
{
"html_attributions" : [],
"result" : {
"name" : "Try Bobry",
"vicinity" : "Dmytra Yavornytskoho Avenue, 42, Dnipro"
},
"status" : "OK"
}
but the original name of this place is Три бобри, not Try Bobry.
You say I can use language=uk parameter to get this name, but if I will use it - it will break another place, which original name is in English, for example this https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJHZkI69zi20ARfbLn6MV6S9o&fields=vicinity,name&key=MY_API_KEY&language=uk will return
{
"html_attributions" : [],
"result" : {
"name" : "Візьміть каву, щоб піти",
"vicinity" : "вулиця Барикадна, 5-7, Дніпро́"
},
"status" : "OK"
}
so it will be Візьміть каву, щоб піти instead of Take coffee to go.
All I want is to get places' names in the language of origin, not translated.

How to access one element of a REST collection through HATEOAS links?

I'm trying to build an architecture of RESTful services, and to build a gateway service for all of those, with Java Spring. In order to make the latter, I need to implement a client for the other services, which me and my colleagues tried to design around the HATEOAS principle, by providing links to related resources through spring-hateoas module.
Let's say I have a service running on localhost, listening on 8080 port, which returns a collection of resources with a GET operation on /resources. For example:
{
"_embedded" : {
"resources" : [ {
"label" : "My first resource!",
"resourceId" : 3,
"_links" : {
"self" : {
"href" : "http://localhost:8080/resources/3"
},
"meals" : {
"href" : "http://localhost:8080/resources",
"templated" : true
}
}
}, {
"label" : "Another resource!",
"resourceId" : 4,
"_links" : {
"self" : {
"href" : "http://localhost:8080/resources/4"
},
"meals" : {
"href" : "http://localhost:8080/resources",
"templated" : true
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/resources",
"templated" : true
}
}
}
I'm trying to use a HATEOAS client such as Traverson. How could I follow a resource element simply by following HATEOAS links? My solution so far has been to add a link to item on my collection, such as follow:
"_links" : {
"self" : {
"href" : "http://localhost:8080/resources",
"templated" : true
},
"item" : {
"href" : "http://localhost:8080/resources/{id}",
"templated" : true
}
}
So then I can replace the id directly in the template with Traverson and follow the result. But is it a good practice? Should I proceed another way?
Simply put, Traverson is meant to find a link.
In the simplest cases, each link has a unique name (rel). By simply providing the name of the rel to Traverson's follow(...) function, it will use the proper LinkDiscoverer and navigate to the corresponding URI of that rel.
This is a Hop.
Since the goal is to navigate the API kind of like following links on a webpage, you must define a chain of hops.
In your case, it's a little more complication, since you have an embedded with multiple items. Asking for the self link isn't straightforward, since you can easily see three on the root document.
Hence Traverson's support for JSON-Path. If you check the reference documentation, it's easy to see that a JSON-Path expression can be supplied to help pick which link you want.
As long as the attribute being selected is the URI, then Traverson will "hop" to it.
NOTE: When simply using rels, you can supply multiple rels as strings in follow(...). When using anything else, like a JSON-Path expression or rel(...), then use one follow(...) per hop. Thankfully, this isn't hard to read of you put each hop on a separate line (again, see ref docs for examples).

Google places API - Can I separate out the output?

Hiting the endpoint:
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Hoboken%20NJ&fields=formatted_address,name&inputtype=textquery&key=xxxxxxxxxxxxxxxxxxx
Getting the result:
{
"candidates" : [
{
"formatted_address" : "New Jersey, USA",
"name" : "Hoboken"
}
],
"debug_log" : {
"line" : []
},
"status" : "OK"
}
What bugs me is that I can't find a way to separate out the region and country - Yes, I know I can parse the result myself. But is there an option I get shoot out to Google Places API to have the response separate out city/state(or region)/country in the returned JSON?
Something like:
{
"candidates" : [
{
"state" : "New Jersey",
"country" : "USA",
"name" : "Hoboken"
}
],
"debug_log" : {
"line" : []
},
"status" : "OK"
}
As far as I know, it isn't possible, you'll have to parse it. Places API is designed to search businesses and POIs at first place.
Google does have, however a geocoding API which seems to give out Postal Code, Country, State, Address, separetely.
There are also some free alternatives

Problems accessing _source fields with a dot in the name when creating Slack action for Elasticsearch Watcher

I am trying to create a Slack action with a dynamic attachment. My _source looks like this:
{
"user.url": "https://api.github.com/users/...",
"user.gists_url": "https://api.github.com/users/.../gists{/gist_id}",
"user.repos_url": "https://api.github.com/users/.../repos",
"date": "2018-04-27T14:34:10Z",
"user.followers_url": "https://api.github.com/users/.../followers",
"user.following_url": "https://api.github.com/users/.../following{/other_user}",
"user.id": 123456,
"user.avatar_url": "https://avatars0.githubusercontent.com/u/123456?v=4",
"user.events_url": "https://api.github.com/users/.../events{/privacy}",
"user.site_admin": false,
"user.html_url": "https://github.com/...",
"user.starred_url": "https://api.github.com/users/.../starred{/owner}{/repo}",
"user.received_events_url": "https://api.github.com/users/.../received_events",
"metric": "stars",
"user.login": "...",
"user.type": "User",
"user.subscriptions_url": "https://api.github.com/users/.../subscriptions",
"user.organizations_url": "https://api.github.com/users/.../orgs",
"user.gravatar_id": ""
}
and here is my Slack action
"actions": {
"notify-slack": {
"throttle_period_in_millis": 240000,
"slack": {
"account": "monitoring",
"message": {
"from": "Elasticsearch Watcher",
"to": [
"#watcher"
],
"text": "We have {{ctx.payload.new.hits.total}} new stars! And {{ctx.payload.old.hits.total}} in total.",
"dynamic_attachments" : {
"list_path" : "ctx.payload.new.hits.hits",
"attachment_template" : {
"title" : "{{_source.[\"user.login\"]}}",
"text" : "Users Count: {{count}}",
"color" : "{{color}}"
}
}
}
}
}
I can't seem to figure out how to access my _source fields since they have dots in them. I have tried:
"{{_source.[\"user.login\"]}}"
"{{_source.user.login}}"
"{{_source.[user.login]}}"
"{{_source.['user.login']}}"
The answer to my question is that you can't access _source keys with dots in them directly using mustache, you must first transform your data.
Update:
I was able to get this working by using a transform to build a new object. Mustache might not be able to access fields with dots in their names, but painless can! I added this transform to my slack object:
"transform" : {
"script" : {
"source" : "['items': ctx.payload.new.hits.hits.collect(user -> ['userName': user._source['user.login']])]",
"lang" : "painless"
}
}
and now in the slack action dynamic attachments, I can access the items array:
"dynamic_attachments" : {
"list_path" : "ctx.payload.items",
"attachment_template" : {
"title" : "{{userName}}",
"text" : "{{_source}}"
}
}
Old Answer:
So according to this Watcher uses mustache.
and according to this mustache can't access fields with dots in the names.

Querying for specific strings in Firebase?

I have a database which looks something like this:
"trucks" : {
"3705ec54-8a2e-4eb1-8bb9-ab2243645ac1" : {
"email" : "sandwiches#123.com",
"name" : "Sandwich Truck",
"phone" : "123 - 456 - 1234",
"provider" : "password",
"selfDescription" : "We serve delicious sandwiches at a moderate price. Cards Accepted.",
"userType" : "truck",
"website" : "www.sandwiches.com"
},
"54fea8cd-2203-46bd-aaf8-9d823e85313d" : {
"email" : "pizza#123.com",
"name" : "Supa Pizza",
"phone" : "619 - 222 - 4444",
"provider" : "password",
"selfDescription" : "We serve incredible pizza at an incredibly unfair price.",
"userType" : "truck",
"website" : ""
},
"6c542367-507c-4d01-af2c-bf93a7efaef4" : {
"email" : "fries#123.com",
"name" : "Pete's Fries",
"phone" : "11111111111111111111",
"profilePhoto" : "",
"provider" : "password",
"selfDescription" : "We make some of the world's most delicious fries.",
"userType" : "truck",
"website" : ""
},
"7c6c4395-aec1-443c-908d-62db517def5e" : {
"email" : "chili#123.com",
"name" : "Mark's Chili",
"phone" : "1-800-CHIL-LLL",
"profilePhoto" : "",
"provider" : "password",
"selfDescription" : "We serve the most delicious chili, chili your mamma's mamma is scared to try.",
"userType" : "truck",
"website" : ""
}
}
I'd like to implement a search bar for which trucks whose names match the search terms will be returned. For example, any truck name containing the string 'fries' will have its ID committed to an array of search result IDs.
Here's what I've tried so far, but no dice. When I type in fries in my searchbar and hit the search button, it does not print "6c542367-507c-4d01-af2c-bf93a7efaef4"
let usersRef = Firebase(url: "https://•••••••••.firebaseIO.com/users")
usersRef.queryOrderedByChild("name").queryEqualToValue(searchBar.text).observeEventType(.ChildAdded, withBlock:{
snapshot in
print(snapshot.key)
})
I'm not even sure how close I am, any help would be massively appreciated.
Thanks!
You are querying using queryEqualToValue (Query.equalTo()), which will return result only if there is an exact match.
Explanation in Detail:
In the search bar if we are entering "fries" it will look for an exact match of "fries", which is not available in our document and hence the desired value "6c542367-507c-4d01-af2c-bf93a7efaef4" is not printed.
Instead if we give the value "Pete's Fries" in the search bar then we will get the result "6c542367-507c-4d01-af2c-bf93a7efaef4"
If we give partial value for our search, then we are trying to implement a search which is similar to LIKE Query in SQL. Please refer the below posts to get more info on "how to perform LIKE query in firebase"
How to perform sql "LIKE" operation on firebase?

Resources