Hey everyone, I’m stuck trying to locate nearby places with Google’s API. For some reason, it’s not giving me any results. I’m using a browser key for the API call and an Android API key in the manifest.
I’ve double-checked my code and API keys, but I’m still getting nothing back. Here’s a snippet of what I’m working with:
fun searchNearbyPlaces() {
val locationCoords = "0.0,0.0"
val searchRadius = 5000
val placeType = "cafe"
val apiKey = "MY_SECRET_KEY"
val url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$locationCoords&radius=$searchRadius&types=$placeType&sensor=true&key=$apiKey"
// Make API call here
// ...
// Process results
if (results.isEmpty()) {
println("No places found nearby")
} else {
for (place in results) {
println("Found: ${place.name}")
}
}
}
Can anyone spot what I might be doing wrong? Any help would be awesome!
I’ve run into similar issues with the Google Places API before. One thing that jumps out at me is your location coordinates. ‘0.0,0.0’ is actually in the middle of the ocean off the coast of Africa! Unless you’re searching for underwater cafes, you’ll want to use real coordinates for your location.
Try using the actual latitude and longitude of the area you’re searching in. You can get these easily from Google Maps. Just right-click on a spot and select ‘What’s here?’ to see the coordinates.
Also, double-check that you’ve enabled the Places API in your Google Cloud Console. Sometimes it’s easy to overlook this step, and it’ll cause the API to return no results.
Lastly, make sure your API key has the necessary permissions. If it’s restricted to certain IP addresses or apps, it might not work in your testing environment.
Hope this helps! Let me know if you’re still having trouble after trying these fixes.
hey john, i had similar probs. make sure ur using real coordinates, not 0.0,0.0 (that’s ocean lol). also check if ur enabled places API in google cloud console. sometimes it’s easy to miss. oh and verify ur API key permissions are set right. good luck man!
I’ve encountered this issue before. Your code may seem correct, but there are a few details to verify. First, check that your API key is accurate and that it has the necessary permissions. Also, make sure the Places API is enabled in your Google Cloud Console. It is important to use valid coordinates because using ‘0.0,0.0’ points to the ocean, which could lead to no results. Additionally, consider whether the search radius fits the intended area and confirm that the place type meets Google’s specified categories. If none of these suggestions resolve the problem, log the entire API response to look for error messages that can offer further insight into the issue. Using Google’s official client libraries might also help manage errors more effectively and simplify implementation.