Google places API next_page_token gives a duplicate of the first page

Viewed 13

It's the first project I've worked with google places api. When I try to get the second page (or more) I keep getting the same 20 results from the first page.

my request looks like so:

 // places api result for the selected circle:
        let {data} = await axios.get(`https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${lat}%2C${lng}&radius=${radius}&key=${key}`);
        let resultData = data;

 // places api list of the places from the result:
        let placesList: Array<any> = resultData.results;
        for (let i = 0; i < 2; i++) {
            if (resultData.next_page_token) {
                const pageToken = resultData.next_page_token;
                let newData = await axios.get(`https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${lat}%2C${lng}&radius=${radius}&key=${key}&pageToken=${pageToken}`);
                resultData = newData.data;
                placesList = [...placesList, ...resultData.results];
            } else {
                return;
            }
        }

did anyone ever run into this problem, and solved it?

0 Answers
Related