Google geocoding api search with Arabic language address - google-maps

I am passing arabic lang search text in Google geocoding api query, but returns no result in json
string strResult="http://maps.googleapis.com/maps/api/geocode/json?address=جدة +السليمانية "&sensor=false&language=ar";
gives
{
"results" : [],
"status" : "INVALID_REQUEST"
}
kindly suggest the correctway of passing arabiclanguage search text in url.

You must encode the address-part, it should be:
http://maps.googleapis.com/maps/api/geocode/json?address=%D8%AC%D8%AF%D8%A9+%2B%D8%A7%D9%84%D8%B3%D9%84%D9%8A%D9%85%D8%A7%D9%86%D9%8A%D8%A9+%22&sensor=false&language=ar
How to encode it depends on the used programming-language

Related

How to get the AutoComplete country list and country code list from Google places?

I am trying to run the following API call.n I am following the API DOC here - https://developers.google.com/maps/documentation/places/web-service/autocomplete#types
https://maps.googleapis.com/maps/api/place/autocomplete/json?
types=regions:country
&input=sri
&key=API_KEY
&language=en
But I am always getting the following output.
{
"predictions": [],
"status": "INVALID_REQUEST"
}
What am I doing wrong here? It is not possible to autocomplete the country list with codes?
In your request, type=regions:country is not valid. You can use type=(regions) like the docs specify:
https://developers.google.com/maps/documentation/places/web-service/autocomplete#types
This is as close as you can get to only countries.
A request like https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&input=sri&key=API_KEY&language=en will return Sri Lanka as first prediction. You could further filter your predictions by looking for only ones with "country" in the "types" field of the response.

How to find gas station using Google Places API?

I'm looking to find gas stations around based on the location I provided. And it seems that the query string that I provide to the Google API is not really correct, leading to the desired result.
Here is the URL
https://maps.googleapis.com/maps/api/place/nearbysearch/json
And this is my query string:
?location=40.316828,%20-82.839840&radius=50000&type=gas_station&keyword=cruise&key=My_Google_Key
Response returned current>:
{
"html_attributions" : [],
"results" : [],
"status" : "ZERO_RESULTS"
}
The solution is simple, just remove the "keyword" parameter then everything will be ok. If this param is declared, the API will only return results with the same value as the param
Here is my original URL:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.316828,%20-82.839840&radius=50000&type=gas_station&keyword=cruise&key=My_Google_Key
Replace with this URL:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.316828,%20-82.839840&radius=50000&type=gas_station&key=My_Google_Key

Python3 // JSON Returns on API with unencoded characters

I have an API that returns information taken via WebScraping (requests, BeautifulSoup, etc), and this information must be returned without characters like \ u *****. I need the return with "ã, é, ê, ç" and etc, because another API (which is not in python) will consume data from this JSON, and also people will read the return of that JSON in a browser.
So, my problem is: How can I return a JSON with UTF-8 (or Latin) encoding in python, since the text I need to output is in Portuguese (BR)?
I've already try to use .enconding("utf-8") in the string before insert that in the JSON, but that didn't work.
For example, when I get the return above, the text returns me an Unencoded text.
Someone can help me, please?
status = "True";
if status == "True":
texto = "Processos"
dataFull = []
stringMsg = "Processo(s) não encontrado(s)"
dataFull.append ({"processos":"","qtdProcessos":"0", "mensagem":stringMsg})
LISTAGEM = {text:dataFull}
return [LISTAGEM[key] for key in sorted(LISTAGEM.keys())]
The return that I expect is:
[
[
{
"mensagem": "Processo(s) não encontrado(s)",
"processos": "",
"qtdProcessos": "0"
}
]
]
But I'm getting, at Chrome browser, when I run the API (localhost:XX/api/v1/processos):
[
[
{
"mensagem": "Processo(s) n\u00e3o encontrado(s)",
"processos": "",
"qtdProcessos": "0"
}
]
]
Can anyone help?

Elasticsearch search templates

I tried using ES's search template to do a conditional clause as specified here. I'm sending my request to the /[my_index]/_search/template endpoint. The request fails because of JSON parsing issues, which makes sense because after adding the conditional clause the payload is no longer a valid JSON. How than am I supposed to use the search templates? Is there a designated endpoint for non-JSON templates?
When using conditional clauses,the template will not be a valid JSON because it will include the section markers {{# like this }}.For this reason, the template should either be stored in a file or, when used via the REST API, should be written as a string.
Method 1 : tempalte stored in a file
Save the query part of the template in config/scripts
ES installation>Config>scripts
test_template.mustache
{
"query":{ whatever query }
}
you can use the saved template by this method through sense
GET /_search/template
{
"template": "test_template",
"params": {
whatever params
}
}
Method 2: template written as a string
convert the template to string form and use via rest api
POST /_search/template/test_template
{
"template": "{\"query\":{ whatever query; remember to escape quotes}}"
}
To search using this template,
GET /_search/template
{
"template": {
"id": "test_template"
},
"params": {
whatever params
}
}
Reference: https://www.elastic.co/guide/en/elasticsearch/reference/1.7/search-template.html#_conditional_clauses
You need to escape the template in wrapping string.
From the same link you referenced:
As written above, this template is not valid JSON because it includes
the section markers like {{#line_no}}. For this reason, the template
should either be stored in a file (see the section called
“Pre-registered templateedit”) or, when used via the REST API, should
be written as a string:
"template":
"{\"query\":{\"filtered\":{\"query\":{\"match\":{\"line\":\"{{text}}\"}},\"filter\":{{{#line_no}}\"range\":{\"line_no\":{{{#start}}\"gte\":\"{{start}}\"{{#end}},{{/end}}{{/start}}{{#end}}\"lte\":\"{{end}}\"{{/end}}}}{{/line_no}}}}}}"

Emitting JSON with optional arguments (Google API)

I'm writing a JSON emitter for a Google API. The API documentation says that some fields are "optional". How am I supposed to interpret that? I've looked at json.org's language specification and it doesn't say. Google's docs are not clear on the subject either.
For example, consider the "sellerData" field in the following:
{
"iss" : "1337133713371337",
"aud" : "Google"
"typ" : "google/payments/inapp/item/v1",
"exp" : "1309988959",
"iat" : "1409988959",
"request" :{
"name" : "Piece of Cake",
"description" : "Virtual chocolate cake to fill your virtual tummy",
"price" : "10.50",
"currencyCode" : "USD",
"sellerData" : "user_id:1224245,offer_code:3098576987,affiliate:aksdfbovu9j"
}
}
If I didn't have any "sellerData" to send, should I just send "sellerData": Null or just not put the field in at all? The former would make my emitter code much cleaner.
Optional fields can be completely omitted.
If you do not need "sellerData", do not add it to the JSON.
Once you set up a merchant sandbox account, the online documentation has a JWT generation tool that let's you experiment with setting various field values.
You can also double check your JWT creation with the JWT Decoder tool.