Google Maps API -is not showing all cities - google-maps

I would like to use Google Maps API to find all cities contains entered name.
I tried to use:
https://maps.googleapis.com/maps/api/place/autocomplete/json?&input=Poznań&types=(cities)&language=pl&key=[MyKey]
This request returned 5 cities:
"Poznań, Polska"
"Poznanovec, Chorwacja",
"Poznań, Obwód rówieński, Ukraina"
"Poznanovci, Słowenia"
"Sady, Polska"
Two problems:
Query don't return one of city Poznań in Poland (https://goo.gl/maps/B3LjyRdVn7S3DEuu7)
I don't know why query return: "Sady, Polska"
Could you tell me how force API to return all cities contains some name?
Full query return:
{
"predictions" : [
{
"description" : "Poznań, Polska",
"matched_substrings" : [
{
"length" : 6,
"offset" : 0
}
],
"place_id" : "ChIJtwrh7NJEBEcR0b80A5gx6qQ",
"reference" : "ChIJtwrh7NJEBEcR0b80A5gx6qQ",
"structured_formatting" : {
"main_text" : "Poznań",
"main_text_matched_substrings" : [
{
"length" : 6,
"offset" : 0
}
],
"secondary_text" : "Polska"
},
"terms" : [
{
"offset" : 0,
"value" : "Poznań"
},
{
"offset" : 8,
"value" : "Polska"
}
],
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Poznanovec, Chorwacja",
"matched_substrings" : [
{
"length" : 6,
"offset" : 0
}
],
"place_id" : "ChIJMduuD-nmZUcRKLHqfF4Ty0w",
"reference" : "ChIJMduuD-nmZUcRKLHqfF4Ty0w",
"structured_formatting" : {
"main_text" : "Poznanovec",
"main_text_matched_substrings" : [
{
"length" : 6,
"offset" : 0
}
],
"secondary_text" : "Chorwacja"
},
"terms" : [
{
"offset" : 0,
"value" : "Poznanovec"
},
{
"offset" : 12,
"value" : "Chorwacja"
}
],
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Poznań, Obwód rówieński, Ukraina",
"matched_substrings" : [
{
"length" : 6,
"offset" : 0
}
],
"place_id" : "ChIJM8yYp2JZKEcRROf2JFonEiA",
"reference" : "ChIJM8yYp2JZKEcRROf2JFonEiA",
"structured_formatting" : {
"main_text" : "Poznań",
"main_text_matched_substrings" : [
{
"length" : 6,
"offset" : 0
}
],
"secondary_text" : "Obwód rówieński, Ukraina"
},
"terms" : [
{
"offset" : 0,
"value" : "Poznań"
},
{
"offset" : 8,
"value" : "Obwód rówieński"
},
{
"offset" : 25,
"value" : "Ukraina"
}
],
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Poznanovci, Słowenia",
"matched_substrings" : [
{
"length" : 6,
"offset" : 0
}
],
"place_id" : "ChIJs5Z1s_IXb0cRGcz67oYV9SA",
"reference" : "ChIJs5Z1s_IXb0cRGcz67oYV9SA",
"structured_formatting" : {
"main_text" : "Poznanovci",
"main_text_matched_substrings" : [
{
"length" : 6,
"offset" : 0
}
],
"secondary_text" : "Słowenia"
},
"terms" : [
{
"offset" : 0,
"value" : "Poznanovci"
},
{
"offset" : 12,
"value" : "Słowenia"
}
],
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Sady, Polska",
"matched_substrings" : [
{
"length" : 4,
"offset" : 0
}
],
"place_id" : "ChIJ-TKnSCVHBEcRGR5C_UOhHhY",
"reference" : "ChIJ-TKnSCVHBEcRGR5C_UOhHhY",
"structured_formatting" : {
"main_text" : "Sady",
"main_text_matched_substrings" : [
{
"length" : 4,
"offset" : 0
}
],
"secondary_text" : "Polska"
},
"terms" : [
{
"offset" : 0,
"value" : "Sady"
},
{
"offset" : 6,
"value" : "Polska"
}
],
"types" : [ "locality", "political", "geocode" ]
}
],
"status" : "OK"
}

You can add components parameter to guarantee that the results of the Places Autocomplete API will be restricted to a certain country.
Here's a working example:
https://maps.googleapis.com/maps/api/place/autocomplete/json?&input=Poznań&types=(cities)&components=country:PL&key=YOUR_API_KEY
There,Poznań, Poland is in the result, and no Sady, Polska.

Related

SwiftyJSON parsing data in array of objects

I am trying to get the value for "name" in the tracks section of JSON. The following JSON is from Spotify. I am using SwiftyJSON for parsing the data.
I am able to pull values from the base json. But once I try to pull anything in the "track" section I get errors.
Here is a sample of the code I got working
let swiftJSON = try? JSON(data: data)
let addedAT = swiftJSON!["items"].arrayValue.map {$0["added_at"].stringValue}
print(addedAT)
{
"items" : [
{
"video_thumbnail" : {
"url" : null
},
"track" : {
"is_playable" : true,
"type" : "track",
"id" : "3F5CgOj3wFlRv51JsHbxhe",
"track" : true,
"duration_ms" : 218364,
"explicit" : true,
"uri" : "spotify:track:3F5CgOj3wFlRv51JsHbxhe",
"is_local" : false,
"artists" : [
{
"external_urls" : {
"spotify" : "https:\/\/open.spotify.com\/artist\/3TVXtAsR1Inumwj472S9r4"
},
"uri" : "spotify:artist:3TVXtAsR1Inumwj472S9r4",
"type" : "artist",
"href" : "https:\/\/api.spotify.com\/v1\/artists\/3TVXtAsR1Inumwj472S9r4",
"name" : "Drake",
"id" : "3TVXtAsR1Inumwj472S9r4"
},
{
"external_urls" : {
"spotify" : "https:\/\/open.spotify.com\/artist\/1URnnhqYAYcrqrcwql10ft"
},
"uri" : "spotify:artist:1URnnhqYAYcrqrcwql10ft",
"type" : "artist",
"href" : "https:\/\/api.spotify.com\/v1\/artists\/1URnnhqYAYcrqrcwql10ft",
"name" : "21 Savage",
"id" : "1URnnhqYAYcrqrcwql10ft"
}
],
"album" : {
"name" : "Honestly, Nevermind",
"total_tracks" : 14,
"external_urls" : {
"spotify" : "https:\/\/open.spotify.com\/album\/3cf4iSSKd8ffTncbtKljXw"
},
"images" : [
{
"height" : 640,
"url" : "https:\/\/i.scdn.co\/image\/ab67616d0000b2738dc0d801766a5aa6a33cbe37",
"width" : 640
},
{
"height" : 300,
"url" : "https:\/\/i.scdn.co\/image\/ab67616d00001e028dc0d801766a5aa6a33cbe37",
"width" : 300
},
{
"height" : 64,
"url" : "https:\/\/i.scdn.co\/image\/ab67616d000048518dc0d801766a5aa6a33cbe37",
"width" : 64
}
],
"artists" : [
{
"external_urls" : {
"spotify" : "https:\/\/open.spotify.com\/artist\/3TVXtAsR1Inumwj472S9r4"
},
"uri" : "spotify:artist:3TVXtAsR1Inumwj472S9r4",
"type" : "artist",
"href" : "https:\/\/api.spotify.com\/v1\/artists\/3TVXtAsR1Inumwj472S9r4",
"name" : "Drake",
"id" : "3TVXtAsR1Inumwj472S9r4"
}
],
"href" : "https:\/\/api.spotify.com\/v1\/albums\/3cf4iSSKd8ffTncbtKljXw",
"release_date_precision" : "day",
"type" : "album",
"id" : "3cf4iSSKd8ffTncbtKljXw",
"album_type" : "album",
"release_date" : "2022-06-17",
"uri" : "spotify:album:3cf4iSSKd8ffTncbtKljXw"
},
"track_number" : 14,
"external_ids" : {
"isrc" : "USUG12204897"
},
"episode" : false,
"external_urls" : {
"spotify" : "https:\/\/open.spotify.com\/track\/3F5CgOj3wFlRv51JsHbxhe"
},
"popularity" : 90,
"disc_number" : 1,
"name" : "Jimmy Cooks (feat. 21 Savage)",
"preview_url" : "https:\/\/p.scdn.co\/mp3-preview\/5feee7c2fed489c933a31ef125aa4ffb5205a457?cid=263c670f8c17484d89d8bd2e6e0964f7",
"href" : "https:\/\/api.spotify.com\/v1\/tracks\/3F5CgOj3wFlRv51JsHbxhe"
},
"added_by" : {
"uri" : "spotify:user:12493212",
"external_urls" : {
"spotify" : "https:\/\/open.spotify.com\/user\/12493212"
},
"type" : "user",
"href" : "https:\/\/api.spotify.com\/v1\/users\/12493212",
"id" : "12493212"
},
"primary_color" : null,
"added_at" : "2022-06-28T16:06:35Z",
"is_local" : false
},
{
"video_thumbnail" : {
"url" : null
},
"track" : {
"is_playable" : true,
"type" : "track",
"id" : "1qMMYpVatbRITKCfq1gasi",
"track" : true,
"duration_ms" : 172933,
"explicit" : true,
"uri" : "spotify:track:1qMMYpVatbRITKCfq1gasi",
"is_local" : false,
"artists" : [
{
"href" : "https:\/\/api.spotify.com\/v1\/artists\/1RyvyyTE3xzB2ZywiAwp0i",
"uri" : "spotify:artist:1RyvyyTE3xzB2ZywiAwp0i",
"name" : "Future",
"id" : "1RyvyyTE3xzB2ZywiAwp0i",
"external_urls" : {
"spotify" : "https:\/\/open.spotify.com\/artist\/1RyvyyTE3xzB2ZywiAwp0i"
},
"type" : "artist"
}
],
"album" : {
"external_urls" : {
"spotify" : "https:\/\/open.spotify.com\/album\/6tE9Dnp2zInFij4jKssysL"
},
"href" : "https:\/\/api.spotify.com\/v1\/albums\/6tE9Dnp2zInFij4jKssysL",
"release_date" : "2022-04-29",
"release_date_precision" : "day",
"artists" : [
{
"href" : "https:\/\/api.spotify.com\/v1\/artists\/1RyvyyTE3xzB2ZywiAwp0i",
"uri" : "spotify:artist:1RyvyyTE3xzB2ZywiAwp0i",
"name" : "Future",
"id" : "1RyvyyTE3xzB2ZywiAwp0i",
"external_urls" : {
"spotify" : "https:\/\/open.spotify.com\/artist\/1RyvyyTE3xzB2ZywiAwp0i"
},
"type" : "artist"
}
],
"name" : "I NEVER LIKED YOU",
"type" : "album",
"album_type" : "album",
"id" : "6tE9Dnp2zInFij4jKssysL",
"uri" : "spotify:album:6tE9Dnp2zInFij4jKssysL",
"images" : [
{
"height" : 640,
"width" : 640,
"url" : "https:\/\/i.scdn.co\/image\/ab67616d0000b27386badd635b69aea887862214"
},
{
"height" : 300,
"width" : 300,
"url" : "https:\/\/i.scdn.co\/image\/ab67616d00001e0286badd635b69aea887862214"
},
{
"height" : 64,
"width" : 64,
"url" : "https:\/\/i.scdn.co\/image\/ab67616d0000485186badd635b69aea887862214"
}
],
"total_tracks" : 16
},
"track_number" : 5,
"external_ids" : {
"isrc" : "USSM12203787"
},
"episode" : false,
"external_urls" : {
"spotify" : "https:\/\/open.spotify.com\/track\/1qMMYpVatbRITKCfq1gasi"
},
"popularity" : 83,
"disc_number" : 1,
"name" : "PUFFIN ON ZOOTIEZ",
"preview_url" : "https:\/\/p.scdn.co\/mp3-preview\/ff3bd626fd7f0bd6af4a429b3119b06ff0aee089?cid=263c670f8c17484d89d8bd2e6e0964f7",
"href" : "https:\/\/api.spotify.com\/v1\/tracks\/1qMMYpVatbRITKCfq1gasi"
},
"added_by" : {
"external_urls" : {
"spotify" : "https:\/\/open.spotify.com\/user\/12493212"
},
"uri" : "spotify:user:12493212",
"type" : "user",
"id" : "12493212",
"href" : "https:\/\/api.spotify.com\/v1\/users\/12493212"
},
"primary_color" : null,
"added_at" : "2022-06-28T16:53:13Z",
"is_local" : false
}
],
"href" : "https:\/\/api.spotify.com\/v1\/playlists\/1nJflwAwbyhpQzKksqwC7H\/tracks?offset=0&limit=100&market=ES&locale=en-US;q=1.0",
"offset" : 0,
"previous" : null,
"limit" : 100,
"next" : null,
"total" : 2
}

Elasticsearch aggregation - groupby & filter max of those document and group by again

I am trying to put a query to elasticsearch(ES) to do calculation for me with the condition following the example data,
{user_id: 1, score: 10, status: passed, date: 2020-02-26},
{user_id: 1, score: 10, status: passed, date: 2020-02-25},
{user_id: 1, score: 8, status: passed, date: 2020-02-25},
{user_id: 1, score: 4, status: failed, date: 2020-02-27},
{user_id: 2, score: 5, status: passed, date: 2020-02-26},
{user_id: 2, score: 6, status: passed, date: 2020-02-25},
{user_id: 3, score: 1, status: failed, date: 2020-02-25},
{user_id: 3, score: 1, status: failed, date: 2020-02-25},
{user_id: 4, score: 7, status: passed, date: 2020-02-25}
{user_id: 4, score: 2, status: failed, date: 2020-02-26}
{user_id: 5, score: 0, status: failed, date: 2020-02-25}
I'd like to get max score(not score of es) of each user_id for counting number of status in each duration (group by status again)
or step: group by user_id get top score record, and group by those status
sample output:
{
"passed":3
"failed":2
"date": 2020-02-25
},
{
"passed":2
"failed":1
"date": 2020-02-26
},
{
"passed":0
"failed":1
"date": 2020-02-27
}
even, I play with SQL it still not easy to solve coz, I cannot get a row_number of record making the result can be wrong (please correct me If I am wrong)
with SQL It like
// this nested query give a wrong answer, just to be an example
// I still playing with it
select user_id, status from table t1 inner join (
select user_id, max(score)
from table
where date = '2020-02-25'
group by user_id, max(score)
) table t2 on t1.user_id = t2.user_id and t1.score = t2.score
group by t1.status
a reason, I want to do this coz, my work have data stored in es and I think it may be good if es could do this as well to reduce performance load of backend side.
Thank you in advance and so open to any suggestion
I have used term aggregation to get count of docs under date and status. Let me know if it works for you.
Sample mapping
PUT testindex13
{
"mappings": {
"properties": {
"userid": {
"type": "keyword"
},
"score": {
"type": "integer"
},
"status": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"date":{
"type": "date",
"format": "yyyy-MM-dd"
}
}
}
}
Data:
"hits" : [
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "9XtAhXABqQAB2FLojE2i",
"_score" : 1.0,
"_source" : {
"user_id" : 1,
"score" : 10,
"status" : "passed",
"date" : "2020-02-26"
}
},
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "9ntAhXABqQAB2FLojU0l",
"_score" : 1.0,
"_source" : {
"user_id" : 1,
"score" : 10,
"status" : "passed",
"date" : "2020-02-25"
}
},
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "93tAhXABqQAB2FLojk2P",
"_score" : 1.0,
"_source" : {
"user_id" : 1,
"score" : 8,
"status" : "passed",
"date" : "2020-02-25"
}
},
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "-HtAhXABqQAB2FLoj02H",
"_score" : 1.0,
"_source" : {
"user_id" : 1,
"score" : 4,
"status" : "failed",
"date" : "2020-02-27"
}
},
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "-XtAhXABqQAB2FLokE0m",
"_score" : 1.0,
"_source" : {
"user_id" : 2,
"score" : 5,
"status" : "passed",
"date" : "2020-02-26"
}
},
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "-ntAhXABqQAB2FLokU2x",
"_score" : 1.0,
"_source" : {
"user_id" : 2,
"score" : 6,
"status" : "passed",
"date" : "2020-02-25"
}
},
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "-3tEhXABqQAB2FLoS00O",
"_score" : 1.0,
"_source" : {
"user_id" : 1,
"score" : 10,
"status" : "passed",
"date" : "2020-02-26"
}
},
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "_HtEhXABqQAB2FLoTE0W",
"_score" : 1.0,
"_source" : {
"user_id" : 3,
"score" : 1,
"status" : "failed",
"date" : "2020-02-25"
}
},
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "_XtEhXABqQAB2FLoTE2L",
"_score" : 1.0,
"_source" : {
"user_id" : 3,
"score" : 1,
"status" : "failed",
"date" : "2020-02-25"
}
},
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "_ntEhXABqQAB2FLoTU2P",
"_score" : 1.0,
"_source" : {
"user_id" : 4,
"score" : 7,
"status" : "passed",
"date" : "2020-02-25"
}
}
]
Query:
GET testindex13/_search
{
"size": 0,
"aggs": {
"Date": {
"terms": {
"field": "date"
},
"aggs": {
"Status": {
"terms": {
"field": "status.keyword",
"size": 10
},
"aggs": {
"Count": {
"value_count": {
"field": "user_id"
}
}
}
}
}
}
}
}
Result:
"hits" : {
"total" : {
"value" : 12,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"Date" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : 1582588800000,
"key_as_string" : "2020-02-25",
"doc_count" : 7,
"Status" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "passed",
"doc_count" : 4,
"Count" : {
"value" : 4
}
},
{
"key" : "failed",
"doc_count" : 3,
"Count" : {
"value" : 3
}
}
]
}
},
{
"key" : 1582675200000,
"key_as_string" : "2020-02-26",
"doc_count" : 4,
"Status" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "passed",
"doc_count" : 3,
"Count" : {
"value" : 3
}
},
{
"key" : "failed",
"doc_count" : 1,
"Count" : {
"value" : 1
}
}
]
}
},
{
"key" : 1582761600000,
"key_as_string" : "2020-02-27",
"doc_count" : 1,
"Status" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "failed",
"doc_count" : 1,
"Count" : {
"value" : 1
}
}
]
}
}
]
}
}
}
EDIT 2. using sort to return top most user by score
GET testindex13/_search
{
"size": 0,
"aggs": {
"Date": {
"terms": {
"field": "date"
},
"aggs": {
"Status": {
"terms": {
"field": "status.keyword",
"size": 10
},
"aggs": {
"Users":{
"terms": {
"field": "user_id",
"size": 10
},
"aggs": {
"TopDocuments": {
"top_hits": {
"size": 1,
"sort": {"score":{"order" : "desc"}}
}
}
}
},
"Count": {
"value_count": {
"field": "user_id"
}
}
}
}
}
}
}
}
Result:
"aggregations" : {
"Date" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : 1582588800000,
"key_as_string" : "2020-02-25",
"doc_count" : 7,
"Status" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "passed",
"doc_count" : 4,
"Count" : {
"value" : 4
},
"Users" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : 1,
"doc_count" : 2,
"TopDocuments" : {
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "9ntAhXABqQAB2FLojU0l",
"_score" : null,
"_source" : {
"user_id" : 1,
"score" : 10,
"status" : "passed",
"date" : "2020-02-25"
},
"sort" : [
10
]
}
]
}
}
},
{
"key" : 2,
"doc_count" : 1,
"TopDocuments" : {
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "-ntAhXABqQAB2FLokU2x",
"_score" : null,
"_source" : {
"user_id" : 2,
"score" : 6,
"status" : "passed",
"date" : "2020-02-25"
},
"sort" : [
6
]
}
]
}
}
},
{
"key" : 4,
"doc_count" : 1,
"TopDocuments" : {
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "_ntEhXABqQAB2FLoTU2P",
"_score" : null,
"_source" : {
"user_id" : 4,
"score" : 7,
"status" : "passed",
"date" : "2020-02-25"
},
"sort" : [
7
]
}
]
}
}
}
]
}
},
{
"key" : "failed",
"doc_count" : 3,
"Count" : {
"value" : 3
},
"Users" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : 3,
"doc_count" : 2,
"TopDocuments" : {
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "_HtEhXABqQAB2FLoTE0W",
"_score" : null,
"_source" : {
"user_id" : 3,
"score" : 1,
"status" : "failed",
"date" : "2020-02-25"
},
"sort" : [
1
]
}
]
}
}
},
{
"key" : 5,
"doc_count" : 1,
"TopDocuments" : {
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "AHtEhXABqQAB2FLoT04D",
"_score" : null,
"_source" : {
"user_id" : 5,
"score" : 0,
"status" : "failed",
"date" : "2020-02-25"
},
"sort" : [
0
]
}
]
}
}
}
]
}
}
]
}
},
{
"key" : 1582675200000,
"key_as_string" : "2020-02-26",
"doc_count" : 4,
"Status" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "passed",
"doc_count" : 3,
"Count" : {
"value" : 3
},
"Users" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : 1,
"doc_count" : 2,
"TopDocuments" : {
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "9XtAhXABqQAB2FLojE2i",
"_score" : null,
"_source" : {
"user_id" : 1,
"score" : 10,
"status" : "passed",
"date" : "2020-02-26"
},
"sort" : [
10
]
}
]
}
}
},
{
"key" : 2,
"doc_count" : 1,
"TopDocuments" : {
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "-XtAhXABqQAB2FLokE0m",
"_score" : null,
"_source" : {
"user_id" : 2,
"score" : 5,
"status" : "passed",
"date" : "2020-02-26"
},
"sort" : [
5
]
}
]
}
}
}
]
}
},
{
"key" : "failed",
"doc_count" : 1,
"Count" : {
"value" : 1
},
"Users" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : 4,
"doc_count" : 1,
"TopDocuments" : {
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "_3tEhXABqQAB2FLoTU3v",
"_score" : null,
"_source" : {
"user_id" : 4,
"score" : 2,
"status" : "failed",
"date" : "2020-02-26"
},
"sort" : [
2
]
}
]
}
}
}
]
}
}
]
}
},
{
"key" : 1582761600000,
"key_as_string" : "2020-02-27",
"doc_count" : 1,
"Status" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "failed",
"doc_count" : 1,
"Count" : {
"value" : 1
},
"Users" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : 1,
"doc_count" : 1,
"TopDocuments" : {
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "testindex13",
"_type" : "_doc",
"_id" : "-HtAhXABqQAB2FLoj02H",
"_score" : null,
"_source" : {
"user_id" : 1,
"score" : 4,
"status" : "failed",
"date" : "2020-02-27"
},
"sort" : [
4
]
}
]
}
}
}
]
}
}
]
}
}
]
}
}

Same request to Google Maps API works differently on various machines

I registered API key, and compossed the following url with it:
https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=Belarus,Minsk,Kuprevicha,1/2&destinations=Belarus,Minsk,Kurchatova,8&key=AIzaSyBngdHtfv-gbJkhKbsgJMqU5T-BnacZuPI
I am getting responce where street information were erased:
{
"destination_addresses" : [ "Minsk, Belarus" ],
"origin_addresses" : [ "Minsk, Belarus" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "1 m",
"value" : 0
},
"duration" : {
"text" : "1 min",
"value" : 0
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
My colleague sitting next to me firing same request recieves a correct full responce.
{
"destination_addresses" : [ "ул. Курчатова 8, Минск, Беларусь" ],
"origin_addresses" : [
"ул. Академика Купревича 1/2, Минск 220141, Беларусь"
],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "24,5 км",
"value" : 24526
},
"duration" : {
"text" : "20 мин.",
"value" : 1196
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
What is the reason of this weird behavior?

How can I find place address using google place search API

Using google place search API, I am able to find place name as shown below. However I am not able to get the address of the place.
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
alert(place.name);
If you are using the Google Place API and have the Server key for that, you can request the data from the API as follows:
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=AddYourOwnKeyHere
Where the "place_id" is the parameter which is responsible for fetching out the details of that particular place. The output is in form of JSON/XML consisting of long name, short name, phone number, time, address, URL etc. You can parse the address and displace in your website/app.
For more details click this link
JSON format:
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "48",
"short_name" : "48",
"types" : [ "street_number" ]
},
{
"long_name" : "Pirrama Road",
"short_name" : "Pirrama Road",
"types" : [ "route" ]
},
{
"long_name" : "Pyrmont",
"short_name" : "Pyrmont",
"types" : [ "locality", "political" ]
},
{
"long_name" : "NSW",
"short_name" : "NSW",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "AU",
"short_name" : "AU",
"types" : [ "country", "political" ]
},
{
"long_name" : "2009",
"short_name" : "2009",
"types" : [ "postal_code" ]
}
],
"events" : [
{
"event_id" : "9lJ_jK1GfhX",
"start_time" : 1293865200,
"summary" : "<p>A visit from author John Doe, who will read from his latest book.</p>
<p>A limited number of signed copies will be available.</p>",
"url" : "http://www.example.com/john_doe_visit.html"
}
],
"formatted_address" : "48 Pirrama Road, Pyrmont NSW, Australia",
"formatted_phone_number" : "(02) 9374 4000",
"geometry" : {
"location" : {
"lat" : -33.8669710,
"lng" : 151.1958750
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "4f89212bf76dde31f092cfc14d7506555d85b5c7",
"international_phone_number" : "+61 2 9374 4000",
"name" : "Google Sydney",
"place_id" : "ChIJN1t_tDeuEmsRUsoyG83frY4",
"scope" : "GOOGLE",
"alt_ids" : [
{
"place_id" : "D9iJyWEHuEmuEmsRm9hTkapTCrk",
"scope" : "APP"
}
],
"rating" : 4.70,
"reference" : "CnRsAAAA98C4wD-VFvzGq-KHVEFhlHuy1TD1W6UYZw7KjuvfVsKMRZkbCVBVDxXFOOCM108n9PuJMJxeAxix3WB6B16c1p2bY1ZQyOrcu1d9247xQhUmPgYjN37JMo5QBsWipTsnoIZA9yAzA-0pnxFM6yAcDhIQbU0z05f3xD3m9NQnhEDjvBoUw-BdcocVpXzKFcnMXUpf-nkyF1w",
"reviews" : [
{
"aspects" : [
{
"rating" : 3,
"type" : "quality"
}
],
"author_name" : "Simon Bengtsson",
"author_url" : "https://plus.google.com/104675092887960962573",
"language" : "en",
"rating" : 5,
"text" : "Just went inside to have a look at Google. Amazing.",
"time" : 1338440552869
},
{
"aspects" : [
{
"rating" : 3,
"type" : "quality"
}
],
"author_name" : "Felix Rauch Valenti",
"author_url" : "https://plus.google.com/103291556674373289857",
"language" : "en",
"rating" : 5,
"text" : "Best place to work :-)",
"time" : 1338411244325
},
{
"aspects" : [
{
"rating" : 3,
"type" : "quality"
}
],
"author_name" : "Chris",
"language" : "en",
"rating" : 5,
"text" : "Great place to work, always lots of free food!",
"time" : 1330467089039
}
],
"types" : [ "establishment" ],
"url" : "http://maps.google.com/maps/place?cid=10281119596374313554",
"vicinity" : "48 Pirrama Road, Pyrmont",
"website" : "http://www.google.com.au/"
},
"status" : "OK"
}
Hope this would help!!

Google Places bad data

Some Places Detail provided by Google Places are not correct.
For example if you type Serengeti National Park in the Autocomplete, you have :
{ "predictions" : [
{
"description" : "Serengeti National Park, Serengeti, Mara, Tanzania",
"id" : "08bd9d4d10a2c77c36987c118a638ba8f75fb2f1",
"matched_substrings" : [
{
"length" : 23,
"offset" : 0
}
],
"reference" : "CkRAAAAAWmw4d0BvC9XVNF73sDnNPiQ841LRJ02RiaLxFonlOJmvmbP01nFpaJVfQVTa1lJScXHCOGtu9P83kUOYAd7f2xIQ_KqR0A_Sbhg8qvEEaIwlEBoU1dU8yFyfIhcZFfRNpdNGpacv6V8",
"terms" : [
{
"offset" : 0,
"value" : "Serengeti National Park"
},
{
"offset" : 25,
"value" : "Serengeti"
},
{
"offset" : 36,
"value" : "Mara"
},
{
"offset" : 42,
"value" : "Tanzania"
}
],
"types" : [ "establishment", "geocode" ]
} ], "status" : "OK" }
Which is ok. Note the description: Serengeti National Park, Serengeti, Mara, Tanzania.
However if you access the Google Places Details you have this:
{
"debug_info" : [],
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "Serengeti",
"short_name" : "Serengeti",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Mara",
"short_name" : "Mara",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "TZ",
"short_name" : "TZ",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Tanzania",
"geometry" : {
"location" : {
"lat" : -2.333333,
"lng" : 34.833333
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "08bd9d4d10a2c77c36987c118a638ba8f75fb2f1",
"name" : "Serengeti National Park",
...
},
"status" : "OK"
}
We can see that the formatted address isn't correct, the country name is TZ instead of Tanzania, etc.
I want to pass this data to the Geocoding so I can have a viewport and other geometry data, but for that I need a proper address, like the one given in the predictions.description.
Is there a way to get this data upon selction of this place in the autocomplete?
Or is there another way to get information needed to geocode this place?
Thanks a lot