This endpoint will retrieve maps data from a Google Maps search and transform it into usable JSON.
Copy 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();
}
}
}
Copy 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();
}
}
}
Copy {
"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"
}
Copy {
"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
}