The request https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=10,10&key=MY_API_KEY
returns INVALID_REQUEST
status.
Why doesn't it work?
CodePudding user response:
Although the documentation doesn't say so
location
The point around which to retrieve place information. This must be specified as latitude,longitude.
<snip>
radius
Defines the distance (in meters) within which to return place results. You may bias results to a specified circle by passing a location and a radius parameter. Doing so instructs the Places service to prefer showing results within that circle; results outside of the defined area may still be displayed.
...
Apparently, radius is also required in this instance, when included (along with a valid key), the service returns a response:
without radius:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=10,10&key=API_KEY
result:
{
"html_attributions" : [],
"results" : [],
"status" : "INVALID_REQUEST"
}
with radius:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=10,10&radius=1500&key=API_KEY
result:
{
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : 10.030721,
"lng" : 9.988080399999999
},
"viewport" : {
"northeast" : {
"lat" : 10.03520199843268,
"lng" : 9.996601970331641
},
"southwest" : {
"lat" : 10.00131293531991,
"lng" : 9.975768926313542
}
}
},
"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" : "Lugge",
"place_id" : "ChIJQZZJ8gEcVRARwMIZcx4oNvU",
"reference" : "ChIJQZZJ8gEcVRARwMIZcx4oNvU",
"scope" : "GOOGLE",
"types" : [ "locality", "political" ],
"vicinity" : "Lugge"
}
],
"status" : "OK"
}