I'm working with Google-places-api
in my project.
User finds a city using places-autocomplete
and the city (place_id) is stored in the database. Then they can see for example Countries they visited. The problem is with some cities or localities.
If I choose city Dakhla
, which is in Morocco
resp. Western Sahara
, it doesn't return any country. It returns this json with address Dakhla 73000
.
This is my request:
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJQ2KgOjlIIgwRcgFf7vLbciU&key=
And the response, you can clearly see there is no such thing like country:
{
"html_attributions": [
],
"result": {
"address_components": [
{
"long_name": "Dakhla",
"short_name": "Dakhla",
"types": [
"locality",
"political"
]
},
{
"long_name": "73000",
"short_name": "73000",
"types": [
"postal_code"
]
}
],
"adr_address": "<span class=\"locality\">Dakhla</span> <span class=\"postal-code\">73000</span>",
"formatted_address": "Dakhla 73000",
"geometry": {
"location": {
"lat": 23.7221111,
"lng": -15.9347384
},
"viewport": {
"northeast": {
"lat": 23.7557101,
"lng": -15.9082891
},
"southwest": {
"lat": 23.6551306,
"lng": -15.982863
}
}
},
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id": "4617ad02ab8faa18c1fbfa0d4ad6912184fd5d96",
"name": "Dakhla",
"photos": [
{
"height": 3456,
"html_attributions": [
"<a href=\"https://maps.google.com/maps/contrib/101097515652901724856/photos\">Anass eagles</a>"
],
"photo_reference": "CmRaAAAA2Yed-VeeRRlwAFsiydbMubthP2DKraqL9h2Jm942UZDxlu2WQ7ZgLjOjHC3PaYqMuXsK7r2-pmxxRgFBjXvrgNBp5PzeVatbwZSQF5TGcdc-cqmdJZXMy-4xqaUD6eQ8EhBGXM0WrdBeM510nkZF2pr3GhSqU0hYlKDx7cAT_tLDUAXQpm3SFw",
"width": 5184
},
{
"height": 482,
"html_attributions": [
"<a href=\"https://maps.google.com/maps/contrib/115265998372124547858/photos\">AN OU AR</a>"
],
"photo_reference": "CmRaAAAAkrItWe0tbch3zTtrTp7VHbNDT9RiZJtq0QBIGc2RHSTgNMHSRWkZ8ZtEC01-CmKCiSRf3AMlEcSTKuEKGuYZMKATIdTxWbwl6NoCle0xza9dW1_4GteLk5UaAaMZOxQ-EhDhG7HOlzFQKiWbcrx_RzIBGhRrFjrqxXA5iO4rlenGjaQC-dvmQQ",
"width": 1280
},
{
"height": 2848,
"html_attributions": [
"<a href=\"https://maps.google.com/maps/contrib/109340304984953152070/photos\">Laasri Photo</a>"
],
"photo_reference": "CmRaAAAAw2NU-MmFfu4xeu42AbUwZfQq9YXvbfXuK6QBCl0651gO-EKW_4SUsM3jSA6TP277sAG77dNsZjoHZ9huVvyzuWyuGupf_49YHuTQIRVxXIXFuzKt8FicASPQ26QqET3XEhBkc5FudE60iEM8QMR5IV5aGhSfAm96l2t19ckVKMAna6dXG0MDwQ",
"width": 4288
}
],
"place_id": "ChIJQ2KgOjlIIgwRcgFf7vLbciU",
"reference": "CmRbAAAA6wvlR94FGET4itrDJ8zgThYhbU2uL4BVphEIKqkdXNpqigNTScX46GqylfK6x2_ETIhYFutmjN3eCIQzFsVHYJYX9n2nHycVa0AxwyJizPrnvFYAIiD8fO_Ib66TJTJoEhBLFH5SDZDZ9DTJuqKkHZsyGhTqn0loCaR8uHfVc1NfeNOMXaiTEQ",
"scope": "GOOGLE",
"types": [
"locality",
"political"
],
"url": "https://maps.google.com/?q=Dakhla+73000&ftid=0xc2248393aa06243:0x2572dbf2ee5f0172",
"utc_offset": 0,
"vicinity": "Dakhla"
},
"status": "OK"
}
What would you do? The country is very important for us.
EDIT:
The only thing which comes to my mind is to try to get country and if there is no such information, use it's coordinates and try another service like OpenStreetMaps
but I would like to avoid working with two different servicies.