Scrape Google Maps search results into structured JSON/CSV with ScraperAPI in Java. Retrieve local business data by query and geolocation for analytics.
This endpoint will retrieve shopping data from an Google Maps Search result page and transform it into usable JSON.
try {String apiKey ="API_KEY";String query ="QUERY";String latitude ="LATITUDE";String longitude ="LONGITUDE";String url ="https://api.scraperapi.com/structured/google/mapssearch?api_key="+ apiKey +"&query="+ query +"&latitude="+ latitude +"&longitude="+ longitude;URL urlForGetRequest =newURL(url);HttpURLConnection connection = (HttpURLConnection) urlForGetRequest.openConnection();connection.setRequestMethod("GET");int responseCode =connection.getResponseCode();if (responseCode ==HttpURLConnection.HTTP_OK) {BufferedReader in =newBufferedReader(new InputStreamReader(connection.getInputStream()));StringBuffer response =newStringBuffer();String readLine;while ((readLine =in.readLine()) !=null) {response.append(readLine);}in.close();System.out.println(response.toString());} else {thrownewException("Error in API Call");}} 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
Note: To fetch additional pages you need to use the next_page_url by adding your unique api_keyparameter at the end.