How can I search Google Maps API and get multiple places? - google-maps-api-3

I've been able to make requests to the Places API from Google Maps, but I always get one result.
For example, searching something like "The White House", or an actual street address, get one single result:
https://maps.googleapis.com/maps/api/place/findplacefromtext/json
?input=the%20white%20house
&inputtype=textquery
&fields=formatted_address,name,geometry
&key=API_KEY
response: {
candidates: [
{
formatted_address: "1600 Pennsylvania Ave NW, Washington, DC 20500, USA",
geometry: {
location: {
lat: 38.8976763,
lng: -77.0365298
},
viewport: {
northeast: {
lat: 38.90148105,
lng: -77.03520012010728
},
southwest: {
lat: 38.89640805000001,
lng: -77.03789977989273
}
}
},
name: "The White House"
}
],
status: "OK"
};
What if I want to find, to be cliche, all the Starbucks around me? (how to limit the search radius is a later question)
https://maps.googleapis.com/maps/api/place/findplacefromtext/json
?input=starbucks
&inputtype=textquery
&fields=formatted_address,name,geometry
&key=API_KEY
response: {
candidates: [],
status: "ZERO_RESULTS"
};
Some comments indicate that I should be getting a different response for my "Starbucks" search. Why aren't I?

You can try Nearby Search. Just please note that there is no way to constrain Nearby Search requests to only return specific fields.
Just look at the sample request below:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=38.8976763%2C-77.0365298&radius=50000&keyword=mcdonalds&key=YOUR_KEY
The response will give you all McDonalds store in this specific location 38.8976763,-77.0365298. You will also notice that there's a radius parameter of 50000 to return the place results.

Related

Redux - updating store based on async api calls

I have a use case to render page using redux with graphql api calls.
On first component will call default action to fetch data from graphql, and stores in redux state as below
state = { films: {
totalCount: 6,
films: [
{
created: '2014-12-10T14:23:31.880000Z',
id: 'ZmlsbXM6MQ==',
director: 'George Lucas',
title: 'A New Hope'
},
{
created: '2014-12-12T11:26:24.656000Z',
id: 'ZmlsbXM6Mg==',
director: 'Irvin Kershner',
title: 'The Empire Strikes Back'
},
{
created: '2014-12-18T10:39:33.255000Z',
id: 'ZmlsbXM6Mw==',
director: 'Richard Marquand',
title: 'Return of the Jedi'
}
]
}
}
and will show UI like below
Films demo app UI screenshot
Once placed in individual component (Film), i have to make service call to get film details by id ( this calls will be async to fetch data and has to store in state.
Will get data as below
{ "data": {
"film": {
"id": "ZmlsbXM6NQ==",
"title": "Attack of the Clones",
"created": "2014-12-20T10:57:57.886000Z",
"director": "George Lucas",
"releaseDate": "2002-05-16",
"episodeID": 2,
"openingCrawl": "There is unrest in the Galactic\r\nSenate. Several thousand solar\r\nsystems have declared their\r\nintentions to leave the Republic.\r\n\r\nSenator Amidala, the former\r\nQueen of Naboo, is returning\r\nto the Galactic Senate to vote\r\non the critical issue of creating\r\nan ARMY OF THE REPUBLIC\r\nto assist the overwhelmed\r\nJedi....",
"producers": [
"Rick McCallum"
]
}
}
}
Now i have to update my state like below, so that i can show all film data in individual (Film) component
state = { films: {
totalCount: 6,
films: [
{
"id": "ZmlsbXM6NQ==",
"title": "Attack of the Clones",
"created": "2014-12-20T10:57:57.886000Z",
"director": "George Lucas",
"releaseDate": "2002-05-16",
"episodeID": 2,
"openingCrawl": "There is unrest in the Galactic\r\nSenate. Several thousand solar\r\nsystems have declared their\r\nintentions to leave the Republic.\r\n\r\nSenator Amidala, the former\r\nQueen of Naboo, is returning\r\nto the Galactic Senate to vote\r\non the critical issue of creating\r\nan ARMY OF THE REPUBLIC\r\nto assist the overwhelmed\r\nJedi....",
"producers": [
"Rick McCallum"
]
},
{
"id": "ZmlsbXM6Mg==",
"title": "The Empire Strikes Back",
"created": "2014-12-12T11:26:24.656000Z",
"director": "Irvin Kershner",
"releaseDate": "2002-05-16",
"episodeID": 2,
"openingCrawl": "There is unrest in the Galactic\r\nSenate. Several thousand solar\r\nsystems have declared their\r\nintentions to leave the Republic.\r\n\r\nSenator Amidala, the former\r\nQueen of Naboo, is returning\r\nto the Galactic Senate to vote\r\non the critical issue of creating\r\nan ARMY OF THE REPUBLIC\r\nto assist the overwhelmed\r\nJedi....",
"producers": [
"Rick McCallum"
]
},
{
"id": "ZmlsbXM6Mw==",
"title": "Return of the Jedi",
"created": "2014-12-18T10:39:33.255000Z",
"director": "Richard Marquand",
"releaseDate": "2002-05-16",
"episodeID": 2,
"openingCrawl": "There is unrest in the Galactic\r\nSenate. Several thousand solar\r\nsystems have declared their\r\nintentions to leave the Republic.\r\n\r\nSenator Amidala, the former\r\nQueen of Naboo, is returning\r\nto the Galactic Senate to vote\r\non the critical issue of creating\r\nan ARMY OF THE REPUBLIC\r\nto assist the overwhelmed\r\nJedi....",
"producers": [
"Rick McCallum"
]
}
]
}
}
When i am trying action to fetch Film by id (async calls using api middleware) in Film component, its calling and trying to update but all actions are looping and not working properly.
Please help me to understand and use redux actions properly.
App Codesandbox link https://codesandbox.io/s/adoring-jang-bf2f8m
Verify the console logs, can see actions looping....
Thanks.
Update::
Updated the above app to #redux/toolkit, below is the ref url
https://codesandbox.io/s/react-rtk-with-graphql-9bl8q7
You are using a highly outdated style of Redux here that will make you write 4 times the code at no benefit - modern Redux does not have ACTION_TYPE constants, switch..case reducers, hand-written middleware (at least in a case like yours), immutable reducer logic or hand-written action creators - all that since 2019. The tutorial you are following is highly outdated and the problems you are facing right now will not be problems for you if you go with the modern style.
Please do yourself a favor and go follow the official Redux tutorial. It also covers getting data from apis in chapters 5, 7 and 8.

How can I request pinpoint accurate geocoding data using HERE Api

I am looking to use HEREs geocoding service to locate the Lat and Lon of a place based on a UK postcode. At the moment my request will return a rough location even though I have provided a full postcode.
The old "geocode" API that I used previously, would return relevant results however this has been put into maintenance and replaced with the "geocode and search" API. This new API seems like it just looks through a list of stored points of interest within HERE’s database and returns the closest it can to what you have searched for, rather than trying to find the exact location entered.
How can I get more accurate results using the below request? Bare in mind that I will only have access to the postcode.
https://geocode.search.hereapi.com/v1/geocode?q={postCode}&apiKey={key}
At the moment I receive a response similar to the below using postcode PE1 1QL. It should be pointing to a car park, however if you enter the lat and lon returned from the API into a map E.g Google Maps, it gives you a more general location, rather than an accurate one.
{
"title": "PE1 1, Peterborough, England",
"id": "here:cm:namedplace:22221149",
"resultType": "locality",
"localityType": "postalCode",
"address": {
"label": "PE1 1, Peterborough, England",
"countryCode": "GBR",
"countryName": "England",
"county": "Cambridgeshire",
"city": "Peterborough",
"postalCode": "PE1 1"
},
"position": {
"lat": 52.57362,
"lng": -0.24219
},
"mapView": {
"west": -0.23515,
"south": 52.56739,
"east": -0.25194,
"north": 52.57984
},
"scoring": {
"queryScore": 0.67,
"fieldScore": {
"postalCode": 0.95
}
}
},
I would expect the Lat and Lng to be much closer to the postcode entered than the above example.
Regarding on this release notes https://developer.here.com/documentation/geocoding-search-api/release_notes/topics/known-issues.html
you can read "High precision postal codes are not yet supported":
Known Issues
The following table lists issues known to be present in the current release.
Search for intersections is not yet supported
Search by telephone numbers is not yet supported
Political views are not yet supported. All views are “International”
Places detail views are not yet supported
High precision postal codes are not yet supported
The Geocoder API 6.2 will be supported at least until end of 2020 (maybe more) and "Maintenance" in documentation means: no new features.

Google Distance Matrix API error distance between PARIS and another french city (randow problem)

When i try to calculate the distance between Paris and an other city in France, Google API returns a random result. It returns the right distance or ZERO_RESULTS
I use Postman application. I create GET request :
https://maps.googleapis.com/maps/api/distancematrix/json?units=METRIC&mode=WALKING&origins=BRY SUR MARNE , VAL-DE-MARNE , FR&destinations=PARIS , PARIS , FR&key=MY_KEY
API Google returns :
{
"destination_addresses": [
"4100 Lake Dr SE Suite 300, Grand Rapids, MI 49546, USA"
],
"origin_addresses": [
"94360 Bry-sur-Marne, France"
],
"rows": [
{
"elements": [
{
"status": "ZERO_RESULTS"
}
]
}
],
"status": "OK"
}
This is an intended behavior because the destination address is in the USA while the origin is in France which doesn't have any available routes towards each other, If the destination address is not the intended address, I'd suggest that you supply the well-formatted address to avoid this kind of errors.

Wrong intent in Alexa Skill Request when using the simulator

I set up my intents using this intent schema:
{
"intents": [
{
"intent": "StartIntend"
},
{
"intent": "AMAZON.YesIntent"
},
{
"intent": "AMAZON.NoIntent"
}
]
}
My sample utterances look like this (it's german):
StartIntend Hallo
StartIntend Moin
StartIntend Guten Tag
Why does the Amazon Developer Console generate the following request, when I use the utterance "Yes" or "Ja"?
{
"session": {
"sessionId": "SessionId...",
"application": {
"applicationId": "amzn1.ask.skill...."
},
"attributes": {},
"user": {
"userId": "amzn1.ask.account...."
},
"new": true
},
"request": {
"type": "IntentRequest",
"requestId": "EdwRequestId...",
"locale": "de-DE",
"timestamp": "2017-02-17T21:07:59Z",
"intent": {
"name": "StartIntend",
"slots": {}
}
},
"version": "1.0"
}
Whatever I enter, it always is using the intend StartIntend.
Why is that? What have I forgotten / what have I done wrong?
The schema and utterance look correct.
I tried duplicating what you are seeing by performing the following steps:
Copied them as-is into a new skill on my account
Selected the North America region on the Configuration page.
Set the lambda to point to an existing lambda that I have. For testing purposes, I just need a valid ARN. I'm going to ignore the response anyways.
Then entered "Yes" into the service simulator
It indeed sent the Lambda the AMAZON.YesIntent.
So I conclude that there's nothing with the data you posted.
I tried entering Ja which resulted in the StartIntend, but I guess I would expect that since Ja is not "Yes" in North America.
Have you set the region to Europe, and entered a Lambda for the Europe region?
I talked about it with the Amazon Support. After some experiments it turned out, you have to write "ja" in lowercase. It seems to be a bug in the simulator itself.
When creating the skill in the Alexa Skills Kit, you need to choose the correct language i.e. German, see screenshot below.
Everything else seems to be correct.

Google Places API language=en returns results in other languages

I'm sending the request like this:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?&key=ENTER_YOUR_KEY_HERE&name=&types=restaurant&location=35.79067650569248,107.49634109437466&radius=521711.0&language=en
The query is in China.
and i'm getting results like this:
results: [
{
geometry: {
location: {
lat: 35.737293,
lng: 107.646029
}
},
icon: "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
id: "759bdf36fa8d5182c6cecb8839d21f5db691ab04",
name: "海底捞火锅西峰店",
place_id: "ChIJwQHr9-k9ZjYRkNpSDzYpfTo",
reference: "CnRrAAAAkM6HlYVwL2mO2sefdojOY7cqX9lQtA_OWt2pFzyGW7p6lj-1oSqFnX3q7_iJtDBGIcoRhqMxriUEXCD4Y8QaBZXhX_7IiqgO_2xHYHN9nWEKOYuPWmuj1V5nTy-D_w-im2OcZVoblKayGDuo2xJTiBIQ2DySEk1zgG1UDKHFnzBxTRoUqsR3fT9UOHrRwOj-hQZZygqxiWo",
scope: "GOOGLE",
types: [
"restaurant",
"food",
"point_of_interest",
"establishment"
],
vicinity: "Xifeng, Qingyang"
},
the name is in Chinese. is there something i can do?
MrUpsidown in the comments is correct: there's no English name for this place in Google's database, so returning the Chinese name Google does have is the best the Places API can do here.

Resources