Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:43:38+00:00 2026-06-16T01:43:38+00:00

I am developing an google places API application where my target to get all

  • 0

I am developing an google places API application where my target to get all available details of a specific query. But as I know google places API only returns 20 results at a time.But I need all available place details.

If I search with a search keyword more than once its always gives the same results. So I want to know that is there any way to get different results each time I search with the same keyword.

 <?php 
        $placeSearchURL = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=' . $query . '&sensor=true' . '&key=' . API_KEY;

        $placeSearchJSON = file_get_contents($placeSearchURL);
        $dataArray = json_decode($placeSearchJSON);
        $references = array();
        $detailsOfPlaces = array();

        if (isset($dataArray->status)) {
            switch ($dataArray->status) {
                case 'OK' :
                    foreach( $dataArray->results as $details) {
                        $references[] = $details->reference;
                    }
                    break;
                default:
                    echo "Something wrong";
            }
        }

        foreach ($references as $reference) {
            $placeDetailsURL = 'https://maps.googleapis.com/maps/api/place/details/json?reference=' . $reference . '&sensor=true&key=' . API_KEY;
            $placeDetails =file_get_contents($placeDetailsURL);
            $placeDetailsAsArray = json_decode($placeDetails);

            switch ($dataArray->status) {
                case 'OK' :
                    $detailsOfPlace['business_name'] = isset($placeDetailsAsArray->result->name) ? $placeDetailsAsArray->result->name : '';
                    $detailsOfPlace['address'] = isset($placeDetailsAsArray->result->formatted_address) ? $placeDetailsAsArray->result->formatted_address : '';                      

                    $detailsOfPlaces[] = $detailsOfPlace;
                    break;
                default:
                    echo "Something went wrong";
            }
        }

This is my code. It returns 20 results for each query. Can anyone please tell me what adjustment I should made to get 60 results for each query.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:43:40+00:00Added an answer on June 16, 2026 at 1:43 am

    As Chris Green says in his answer you will have to use pagination to get more than 20 results.
    Also as Chris Green also states to take the address you dont really need to make another call to the reference of each place.I am assuming that you will need more information so I just created 2 function implementing what Chris says in his response.
    Not tested so might be some errors but you can get the feeling.

    <?php
    
        function getAllReferences($query, $maxResults= 60, $nextToken = false) {
            $references = array();
            $nextStr = "";
            if ($nextToken)
                $nextStr = "nextpage=$nextToken";
            $placeSearchURL = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=$query&sensor=true&key=".API_KEY."&$nextStr";
            $placeSearchJSON = file_get_contents($placeSearchURL);
            $dataArray = json_decode($placeSearchJSON);
            if (isset($dataArray->status) &&$dataArray->status == "OK") {
                foreach( $dataArray->results as $details) {
                    array_push($references, $details->reference);
                }
                if (!empty($dataArray->next_page_token) && count($references) < $maxResults ) {
                    $nextArray = getAllReferences($query, $maxResults-20 , $dataArray->next_page_token);
                    $references = array_merge($references, $nextArray);
    
                }
                return $references;
            }
        }
    
        function getPlaceFromReference($reference) {
            $placeDetailsURL = 'https://maps.googleapis.com/maps/api/place/details/json?reference=' . $reference . '&sensor=true&key='.API_KEY;
            $placeDetailsContent =file_get_contents($placeDetailsURL);
            $placeDetails = json_decode($placeDetailsContent);
            if ($placeDetails->status == "OK")
                return $placeDetails;
            else return false;
        }
    
        $references = getAllReferences("test");
        if (count($references) == 0)
            echo "no results";
        else {
            foreach ($references as $reference) {
                $placeDetails = getPlaceFromReference($reference);
                print_r($placeDetails);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a REST google app engine application. I want to know if it's
i'm developing an android application similar to Google places app. I want a functionality
Iam developing one application.In that i use the google api for getting the location
Iam developing one application.In that i use the google api for getting the location
I'm developing a program using GOogle Places API and it has two functions: searchPlaces
I am developing an android application that uses Google Places autocomplete. When I select
I'm developing a map application in Android. I'm using Google maps API to show
As part of my learning, i am developing a google maps V3 application, to
Iam developing an android app.about google maps API for android i want to ask
I am developing Python application for Google App Engine on MacOS and I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.