# Google Maps Search API (Async)

The `Google Maps Search API` endpoint returns Google Maps Search result page and transform it into usable JSON.

**Single Query Request**

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST \
    -H "Content-Type: application/json" \
    -d '{
            "apiKey": "API_KEY",
            "query": "QUERY",
            "latitude": LATITUDE,
            "longitude": LONGITUDE,
            "callback": {
                "type": "webhook",
                "url": "YYYYYY"
            }
        }' \
    "https://async.scraperapi.com/structured/google/mapssearch"
```

{% endtab %}

{% tab title="Python" %}

```json
import requests

url = "https://async.scraperapi.com/structured/google/mapssearch"
headers = {
    "Content-Type": "application/json"
}
data = {
    "apiKey": "API_KEY",
    "query": "QUERY",
    "latitude": LATITUDE,
    "longitude": LONGITUDE,
    "callback": {
        "type": "webhook",
        "url": "YYYYY"
    }
}

response = requests.post(url, json=data, headers=headers)
print(response.text)
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
import fetch from 'node-fetch';

const options = {
  method: 'POST',
  body: JSON.stringify({
    apiKey: 'API_KEY',
    query: 'QUERY',
    latitude: LATITUDE,
    longitude: LONGITUDE,
    callback: {
      type: 'webhook',
      url: 'YYYYY'
    }
  }),
  headers: {
    'Content-Type': 'application/json',
  },
}

fetch('https://async.scraperapi.com/structured/google/mapssearch', options)
  .then(response => {
    response.text().then(text => console.log(text));
  })
  .catch(error => {
    console.log(error);
  });
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$curl = curl_init();

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

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);
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'json'
require 'uri'

uri = URI('https://async.scraperapi.com/structured/google/mapssearch')
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
request.body = {
  apiKey: 'API_KEY',
  query: 'QUERY',
  latitude: LATITUDE,
  longitude: LONGITUDE,
  callback: {
    type: 'webhook',
    url: 'YYYYY'
  }
}.to_json

begin
  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
    http.request(request)
  end
  puts response.body
rescue => e
  puts "Error: #{e.message}"
end
```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import javax.net.ssl.HttpsURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class Main {
    public static void main(String[] args) {
        try {
            String apiKey = "API_KEY";
            String jsonInputString = "{"
                + "\"apiKey\": \"" + apiKey + "\", "
                + "\"query\": \"QUERY\", "
                + "\"latitude\": LATITUDE, "
                + "\"longitude\": LONGITUDE, "
                + "\"callback\": {"
                + "    \"type\": \"webhook\", "
                + "    \"url\": \"YYYYY\""
                + "}}";

            URL url = new URL("https://async.scraperapi.com/structured/google/mapssearch");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("Accept", "*/*");
            connection.setDoOutput(true);

            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
            }

            int responseCode = connection.getResponseCode();
            StringBuilder response = new StringBuilder();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String readLine;
            while ((readLine = in.readLine()) != null) {
                response.append(readLine);
            }
            in.close();

            if (responseCode == HttpURLConnection.HTTP_OK) {
                System.out.println("Response: " + response.toString());
            } else {
                throw new Exception("Error in API Call: Response code " + responseCode + "\nbody: " + response.toString());
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
```

{% endtab %}
{% endtabs %}

**Multiple Queries Request**

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "apiKey": "API_KEY",
    "jobs": [
      {
        "query": "QUERY1",
        "latitude": LATITUDE_1,
        "longitude": LONGITUDE_1,
        "callback": {
          "type": "webhook",
          "url": "YYYYYY"
        }
      },
      {
        "query": "QUERY2",
        "latitude": LATITUDE_2,
        "longitude": LONGITUDE_2,
        "callback": {
          "type": "webhook",
          "url": "YYYYYY"
        }
      }
    ]
  }' \
  "https://async.scraperapi.com/structured/google/mapssearch"
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://async.scraperapi.com/structured/google/mapssearch"
headers = {
    "Content-Type": "application/json"
}

data = {
    "apiKey": "API_KEY",
    "jobs": [
        {
            "query": "QUERY1",
            "latitude": LATITUDE_1,
            "longitude": LONGITUDE_1,
            "callback": {
                "type": "webhook",
                "url": "YYYYY"
            }
        },
        {
            "query": "QUERY2",
            "latitude": LATITUDE_2,
            "longitude": LONGITUDE_2,
            "callback": {
                "type": "webhook",
                "url": "YYYYY"
            }
        }
    ]
}

response = requests.post(url, json=data, headers=headers)
print(response.text)
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
import fetch from 'node-fetch';

const options = {
  method: 'POST',
  body: JSON.stringify({
    apiKey: 'API_KEY',
    jobs: [
      {
        query: 'QUERY1',
        latitude: LATITUDE_1,
        longitude: LONGITUDE_1,
        callback: {
          type: 'webhook',
          url: 'YYYYY'
        }
      },
      {
        query: 'QUERY2',
        latitude: LATITUDE_2,
        longitude: LONGITUDE_2,
        callback: {
          type: 'webhook',
          url: 'YYYYY'
        }
      }
    ]
  }),
  headers: {
    'Content-Type': 'application/json',
  },
};

fetch('https://async.scraperapi.com/structured/google/mapssearch', options)
  .then(response => response.text())
  .then(text => console.log(text))
  .catch(error => {
    console.error(error);
  });
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$curl = curl_init();

$data = json_encode(array(
    'apiKey' => 'API_KEY',
    'jobs' => array(
        array(
            'query' => 'QUERY1',
            'latitude' => LATITUDE_1,
            'longitude' => LONGITUDE_1,
            'callback' => array(
                'type' => 'webhook',
                'url' => 'YYYYY'
            )
        ),
        array(
            'query' => 'QUERY2',
            'latitude' => LATITUDE_2,
            'longitude' => LONGITUDE_2,
            'callback' => array(
                'type' => 'webhook',
                'url' => 'YYYYY'
            )
        )
    )
));

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);
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'json'
require 'uri'

uri = URI('https://async.scraperapi.com/structured/google/mapssearch')
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')

request.body = {
  apiKey: 'API_KEY',
  jobs: [
    {
      query: 'QUERY1',
      latitude: LATITUDE_1,
      longitude: LONGITUDE_1,
      callback: {
        type: 'webhook',
        url: 'YYYYY'
      }
    },
    {
      query: 'QUERY2',
      latitude: LATITUDE_2,
      longitude: LONGITUDE_2,
      callback: {
        type: 'webhook',
        url: 'YYYYY'
      }
    }
  ]
}.to_json

begin
  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
    http.request(request)
  end
  puts response.body
rescue => e
  puts "Error: #{e.message}"
end
```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import javax.net.ssl.HttpsURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class Main {
    public static void main(String[] args) {
        try {
            String apiKey = "API_KEY";

            String jsonInputString = "{"
                + "\"apiKey\": \"" + apiKey + "\", "
                + "\"jobs\": ["
                + "  {"
                + "    \"query\": \"QUERY1\", "
                + "    \"latitude\": LATITUDE_1, "
                + "    \"longitude\": LONGITUDE_1, "
                + "    \"callback\": {"
                + "      \"type\": \"webhook\", "
                + "      \"url\": \"YYYYY\""
                + "    }"
                + "  },"
                + "  {"
                + "    \"query\": \"QUERY2\", "
                + "    \"latitude\": LATITUDE_2, "
                + "    \"longitude\": LONGITUDE_2, "
                + "    \"callback\": {"
                + "      \"type\": \"webhook\", "
                + "      \"url\": \"YYYYY\""
                + "    }"
                + "  }"
                + "]"
                + "}";

            URL url = new URL("https://async.scraperapi.com/structured/google/mapssearch");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("Accept", "*/*");
            connection.setDoOutput(true);

            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
            }

            int responseCode = connection.getResponseCode();
            StringBuilder response = new StringBuilder();

            BufferedReader in = new BufferedReader(new InputStreamReader(
                responseCode >= 400 ? connection.getErrorStream() : connection.getInputStream()
            ));

            String readLine;
            while ((readLine = in.readLine()) != null) {
                response.append(readLine);
            }
            in.close();

            if (responseCode == HttpURLConnection.HTTP_OK) {
                System.out.println("Response: " + response.toString());
            } else {
                throw new Exception("Error in API Call: Response code " + responseCode + "\nbody: " + response.toString());
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="success" %}
You can easily get the `latitude` and `longitude` for any location directly from Google Maps by right-clicking on the desired point and copying the coordinates.
{% endhint %}

**Supported Parameters**

<table><thead><tr><th width="261">Parameter</th><th>Details</th></tr></thead><tbody><tr><td><code>API_KEY</code>(required)</td><td>Your API Key.</td></tr><tr><td><code>QUERY</code>(required)</td><td>Query string for example: <code>vegan restaurant</code></td></tr><tr><td><code>LATITUDE</code>(required)</td><td>Latitude value, for example: <code>21.029738077531196</code></td></tr><tr><td><code>LONGITUDE</code>(required)</td><td>Longitude value, for example: <code>105.85222341863856</code></td></tr></tbody></table>

### Sample Response <a href="#sample-response" id="sample-response"></a>

Single Query Request

```json
{
    "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 Queries Request

```json
{
    "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 <mark style="color:red;">**`response`**</mark> key in the response JSON object. The structure is the same as in the corresponding SYNC data endpoint.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.scraperapi.com/structured-data-endpoints/search-and-insights/google/google-maps-search-api-async.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
