Cloud_Computing_Practical4
Cloud_Computing_Practical4
Develop application to consume Google’s search / Google’s Map RESTful Web service.
To create a simple application that searches for a place using the Google Places API and
retrieves the details from the Google Maps Geocoding API. Steps are as follows:
Downloads Required:
JDK: Java Downloads | Oracle India (x64 MSI Installer)
Apache Tomcat: Apache Tomcat Downloads. (x64 bit Windows zip)
After Downloading JDK, Set the Path in Environment Variables in User Variables > Path >
New and Provide the Variable name and values to set the Path for JDK as shown below:
Demonstration:
Now check the versions that shows path is set for Java JDK
Step 1: Download and Extract apache-tomcat-9.0.98 zip file into folder, and open apache-
tomcat-9.0.98 folder till bin and select the directory path, cut (press backspace) and type
cmd.
Demonstration:
Directory Path (Your directory path depends where you place your apache-tomcat
folder)
Select directory path
Type cmd and command prompt will open to the same directory path
Note:
This Tomcat Server must be kept running in the background by minimizing this
window. Otherwise, the we won’t get the output.
Another way to load Tomcat
Also, in bin folder we will have startup as Windows Batch File, double click Run and it will
load Tomcat.
Step 2: After completing Step 1, Now open apache-tomcat-9.0.98 folder, open a folder name
webapps which is already created in apache-tomcat-9.0.98 folder
Open webapps folder, create a new folder and name it as: myjsp
Step 3: Open myjsp folder and open it with VS Code
<body>
<%
// Fetch latitude and longitude from form inputs
String latParam = request.getParameter("t1");
String longParam = request.getParameter("t2");
// Default values in case parameters are not provided
double lati = 40.7128; // Default latitude (New York)
double longi = -74.0060; // Default longitude (New York)
// If parameters exist, parse them to doubles
if (latParam != null && !latParam.trim().isEmpty()) {
lati = Double.parseDouble(latParam);
}
if (longParam != null && !longParam.trim().isEmpty()) {
longi = Double.parseDouble(longParam);
}
%>
<h3>Google Maps Location</h3>
<div id="map"></div>
<script>
// Initialize the map
function initMap() {
var location = { lat: <%= lati %>, lng: <%= longi %> }; // Use JSP values for lat and
lng
// Create a new map centered on the location
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10, // Zoom level
center: location // Center the map on the provided coordinates
});
Click on Console
Now we can see our new project GoogleMapsAPI and Notifications of new project
We got the API Key Created, Copy the API Key and paste it in myindex.jsp file.
Now, open myjsp folder and open with VS Code and paste the API_KEY in myindex.jsp
script tag:
Shown below:
Before:<!-- Google Maps JavaScript API -->
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY
&callback=initMap" async defer></script>
After: :<!-- Google Maps JavaScript API --><script
src="https://maps.googleapis.com/maps/api/js?
key=AIzaSyAiofE1T6K975oNisc37nvURK7c87XR7e4 &callback=initMap" async
defer></script>
Step 5: Now to check the output, open a web browser Google Chrome or Microsoft Edge
Ctrl + Click to follow the Link, URL: http://localhost:8080/myjsp/myinput.jsp
Demonstration:
-----------------