LogoLogo
OverviewRelease NotesDataPipelineFAQs
Java
Java
  • Make Requests with ScraperAPI in Java
    • Use ScraperAPI Endpoint in Java
    • Use ScraperAPI Proxy Port in Java
    • Use ScraperAPI SDK in Java
    • Make Async Requests with ScraperAPI in Java
      • How to Use ScraperAPI Async Web Scraping in Java
      • Use Async ScraperAPI Callbacks in Java
      • Configure ScraperAPI Parameters in Java
      • Request Async Batch Scraping with ScraperAPI in Java
      • Decode Base64 Async Responses in Java
    • ScraperAPI Structured Data Collection in Java
      • Amazon Product Page API: Structured Data in Java
      • Amazon Search API: Structured Data in Java
      • Amazon Offers API: Structured Data in Java
      • Amazon Reviews API: Structured Data in Java
      • Ebay Product Page API: Structured Data in Java
      • Ebay Search API: Structured Data in Java
      • Google SERP API: Structured Data in Java
      • Google News API: Structured Data in Java
      • Google Jobs API: Structured Data in Java
      • Google Shopping API: Structured Data in Java
      • Google Maps Search API: Structured Data in Java
      • Redfin Agent Details API: Structured Data in Java
      • Redfin 'For Rent' Listings API: Structured Data in Java
      • Redfin 'For Sale' Listings API: Structured Data in Java
      • Redfin Listing Search API: Structured Data in Java
      • Walmart Search API: Structured Data in Java
      • Walmart Category API: Structured Data in Java
      • Walmart Product API: Structured Data in Java
      • Walmart Reviews API: Structured Data in Java
    • ScraperAPI Async Structured Data Collection in Java
      • Amazon Product Page API: Async Structured Data in Java
      • Amazon Search API: Async Structured Data in Java
      • Amazon Offers API: Async Structured Data in Java
      • Amazon Reviews API: Async Structured Data in Java
      • Ebay Product Page API: Async Structured Data in Java
      • Ebay Search API: Async Structured Data in Java
      • Google SERP API: Async Structured Data in Java
      • Google News API: Async Structured Data in Java
      • Google Jobs API: Async Structured Data in Java
      • Google Shopping API: Async Structured Data in Java
      • Google Maps Search API: Async Structured Data in Java
      • Redfin Agent Details API: Async Structured Data in Java
      • Redfin 'For Rent' Listings API: Async Structured Data in Java
      • Redfin 'For Sale' Listings API: Async Structured Data in Java
      • Redfin Listing Search API: Async Structured Data in Java
      • Walmart Search API: Async Structured Data in Java
      • Walmart Category API: Async Structured Data in Java
      • Walmart Product API: Async Structured Data in Java
      • Walmart Reviews API: Async Structured Data in Java
    • Making POST/PUT Requests with ScraperAPI in Java
    • Customizing ScraperAPI Requests in Java
      • Customize Amazon Requests by ZIP Code via ScraperAPI in Java
      • Customize Cached Results via ScraperAPI in Java
      • Customize Control Costs with ScraperAPI Parameter in Java
      • Send Custom Headers with ScraperAPI in Java
      • Customize Device Type with ScraperAPI in Java
      • Customize Geotargeted Content Scrape via ScraperAPI in Java
      • Customize Premium Geotargeted Scrape via ScraperAPI in Java
      • Customize Header Parameter with ScraperAPI in Java
      • Customize Premium Residential/Mobile Proxies in Java
      • Customize JavaScript-Rendered Pages via ScraperAPI in Java
        • Use Render Instruction Set to Scrape Dynamic Pages in Java
        • Customize Taking a Website Screenshots via ScraperAPI in Java
      • Customize Scrape Session-Based Proxies via ScraperAPI in Java
  • Handle and Process Responses via ScraperAPI in Java
    • Use API Status Codes to Retry Failed Requests in Java
    • Customize Output Formats via ScraperAPI Parameters in Java
      • Request JSON Response via Autoparse Parameter in Java
      • Request LLM Output Formats with ScraperAPI in Java
    • Request Response Encoding and Content-Type via ScraperAPI in Java
  • Dashboard & Billing
    • API Key
    • Credit Usage
    • Delete Account
    • Invoice History
    • Billing Email
    • Billing Address
    • VAT Number
    • Payment Method
    • Cancel Subscription
  • Credits and Requests
  • Monitor Your ScraperAPI Account Information in Java
  • Documentation Overview
Powered by GitBook

Quick links

  • Homepage
  • Dashboard
  • Pricing
  • Contact Sales

Resources

  • Developer Guides
  • Blog
  • Contact Support
  • Learning Hub
On this page

Was this helpful?

  1. Make Requests with ScraperAPI in Java
  2. ScraperAPI Async Structured Data Collection in Java

Google Maps Search API: Async Structured Data in Java

Scrape Google Maps search results into structured JSON/CSV with ScraperAPI async in Java. Retrieve local business data by query and geolocation for analytics.

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

Single Query Request:

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 ApiCall {
    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\": \"YYYY\""
                + "}}";

            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();
        }
    }
}

Multiple Query Request:

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 ApiCall {
    public static void main(String[] args) {
        try {
            String apiKey = "API_KEY";
            String jsonInputString = "{"
                + "\"apiKey\": \"" + apiKey + "\", "
                + "\"jobs\": ["
                + "    {"
                + "        \"query\": \"QUERY\", "
                + "        \"latitude\": LATITUDE, "
                + "        \"longitude\": LONGITUDE, "
                + "        \"callback\": {"
                + "            \"type\": \"webhook\", "
                + "            \"url\": \"YYYY\""
                + "        }"
                + "    },"
                + "    {"
                + "        \"query\": \"QUERY\", "
                + "        \"latitude\": LATITUDE, "
                + "        \"longitude\": LONGITUDE, "
                + "        \"callback\": {"
                + "            \"type\": \"webhook\", "
                + "            \"url\": \"YYYY\""
                + "        }"
                + "    }"
                + "]"
                + "}";

            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();
        }
    }
}
Parameter
Details

API_KEY(required)

User's normal API Key

QUERY(required)

Query string for example: vegan restaurant

LATITUDE(required)

Latitude value, for example: 21.029738077531196

LONGITUDE(required)

Longitude value, for example: 105.85222341863856

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.

PreviousGoogle Shopping API: Async Structured Data in JavaNextRedfin Agent Details API: Async Structured Data in Java

Last updated 7 months ago

Was this helpful?