Google Maps Search API (Async)

This endpoint will retrieve maps data from a Google Maps search and transform it into usable JSON.

Single Query Request:

<?php

$curl = curl_init();

$data = json_encode(array(
    'apiKey' => 'API_KEY',
    'query' => 'QUERY',
    'latitude' => LATITUDE,
    'longitude' => LONGITUDE,
    'callback' => array(
        'type' => 'webhook',
        'url' => 'YYYY'
    )
));

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://async.scraperapi.com/structured/google/mapssearch',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => $data,
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

if (curl_errno($curl)) {
    echo 'Error:' . curl_error($curl);
} else {
    echo $response;
}

curl_close($curl);

?>

Multiple Query Request:

<?php

$curl = curl_init();

$data = json_encode(array(
    'apiKey' => 'API_KEY',
    'jobs' => array(
        array(
            'query' => 'QUERY',
            'latitude' => LATITUDE,
            'longitude' => LONGITUDE,
            'callback' => array(
                'type' => 'webhook',
                'url' => 'YYYY'
            )
        ),
        array(
            'query' => 'QUERY',
            'latitude' => LATITUDE,
            'longitude' => LONGITUDE,
            'callback' => array(
                'type' => 'webhook',
                'url' => 'YYYY'
            )
        )
    )
));

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://async.scraperapi.com/structured/google/mapssearch',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => $data,
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

if (curl_errno($curl)) {
    echo 'Error:' . curl_error($curl);
} else {
    echo $response;
}

curl_close($curl);

?>

Sample Response

Single Query Request:

{
    "id": "024559fd-4d71-419c-bda6-2915dda7667d",
    "attempts": 0,
    "status": "running",
    "statusUrl": "https://async.scraperapi.com/jobs/024559fd-4d71-419c-bda6-2915dda7667d",
    "query": "new york restaurants",
    "latitude": 40.74229676764451,
    "longitude": -73.98832638564608,
    "supposedToRunAt": "2024-10-31T09:56:44.748Z"
}

Multiple Query Request:

{
    "id": "0869fa1c-3a0d-4b06-891d-f2e58f5f05cf",
    "attempts": 0,
    "status": "running",
    "statusUrl": "https://async.scraperapi.com/jobs/0869fa1c-3a0d-4b06-891d-f2e58f5f05cf",
    "query": "new york restaurants",
    "latitude": 40.74229676764451,
    "longitude": -73.98832638564608
},

{
    "id": "0f0ed634-e3a0-4b5e-991d-dc10a251c6d7",
    "attempts": 0,
    "status": "running",
    "statusUrl": "https://async.scraperapi.com/jobs/0f0ed634-e3a0-4b5e-991d-dc10a251c6d7",
    "query": "hanoi laundries",
    "latitude": 21.028511,
    "longitude": 105.804817
}

After the job(s) finish, you will find the result under the response key in the response JSON object. The structure is the same as in the corresponding SYNC data endpoint.

Last updated