I'm working in a project where I should display all cities (locality) around 20km from a device location using lat,long.
Moreove, the locality of the device location is not on the result.
Could someone help me?
I precise that I'm not a developer.
Many thanks for your help!
I tried the request below on Postman, but I only have two results rather than more than 10.
Below is the response:
`
{
"html_attributions": [],
"results": [
{
"geometry": {
"location": {
"lat": 48.801408,
"lng": 2.130122
},
"viewport": {
"northeast": {
"lat": 48.82857804347341,
"lng": 2.168480543860636
},
"southwest": {
"lat": 48.77916591232869,
"lng": 2.069908968772275
}
}
},
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/geocode-71.png",
"icon_background_color": "#7B9EB0",
"icon_mask_base_uri": "https://maps.gstatic.com/mapfiles/place_api/icons/v2/generic_pinlet",
"name": "Versailles",
"photos": [
{
"height": 3024,
"html_attributions": [
"<a href=\"https://maps.google.com/maps/contrib/116593793480207812084\">Jessy Velazquez</a>"
],
"photo_reference": "AUjq9jkmbt7CKGCwJfn3ZlpLVC-wGt_1svXYWTyA5p9pgcmd6XCNbEcwAFFjF0xe2tuLIYm5F_42s0Q4dbI0ifJTHZy5-gfzQfSo2jMp_ATL-WfPl3jJHf8WbnRVLSslBCKg3j5jYQBU2pkyb2Tjkk7PLZSGSuv9ycLQu-j2zTBWUM9x-ejT",
"width": 4032
}
],
"place_id": "ChIJvSD0dbR95kcRukqEDa0AnoY",
"reference": "ChIJvSD0dbR95kcRukqEDa0AnoY",
"scope": "GOOGLE",
"types": [
"locality",
"political"
],
"vicinity": "Versailles"
},
{
"geometry": {
"location": {
"lat": 48.7738734,
"lng": 2.0360157
},
"viewport": {
"northeast": {
"lat": 48.7992215538692,
"lng": 2.055979168810353
},
"southwest": {
"lat": 48.75589319907799,
"lng": 1.994393632933018
}
}
},
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/geocode-71.png",
"icon_background_color": "#7B9EB0",
"icon_mask_base_uri": "https://maps.gstatic.com/mapfiles/place_api/icons/v2/generic_pinlet",
"name": "Montigny-le-Bretonneux",
"photos": [
{
"height": 4160,
"html_attributions": [
"<a href=\"https://maps.google.com/maps/contrib/100080658394344210444\">ali imoune</a>"
],
"photo_reference": "AUjq9jn0-yeBGJe57tERWIrudEEdhV_zdqrrtGna1VvH-vI33q2FMfh7c_YaZpK4VXR1eWFhU7MYt0rhxZujTMnM3DL7F5vOXX0zepVThDaB_I5gZ0Io2RjnXbYh4ZDInZ-0aXDY-w4xdisBO_4oAAVgot1516GAbE-He8jvgCacDUcp03w1",
"width": 3120
}
],
"place_id": "ChIJDxMIwS-B5kcRHthZxYnQcNo",
"reference": "ChIJDxMIwS-B5kcRHthZxYnQcNo",
"scope": "GOOGLE",
"types": [
"locality",
"political"
],
"vicinity": "Montigny-le-Bretonneux"
}
],
"status": "OK"
}`
type=localityis not supported by Nearby Search of Places APIPlease see Place Types Documentation.
As you can see on the documentation, the
types=localityis only available in Table 2 and 3:ref: https://developers.google.com/maps/documentation/places/web-service/supported_types#table2
There's a note there that such types are not supported in the
typefilter of a place search.This begs us the question...
How to get the nearest cities?
To be able to get nearby cities using Places API, you can use the Place Autocomplete of Places API.
The Place Autocomplete also have the
types,radius, andlocationparameters that you can use just like the Nearby Search.But since Place Autocomplete is designed to respond to user input and requires an
inputparameter, your users still needs to put something before sending a request.Here's an example request:
The request will only return cities within the circle of this sample map:
Hope this helps!