Ex No 6
Ex No 6
cd locationApp
cordova platform add browser
4. Modify the index.html File
In the www folder of your project, open the index.html file and include a script to fetch
and display the user's current location.
<!DOCTYPE html>
<html>
<head>
<title>Current Location</title>
</head>
<body>
<h1>Find My Location</h1>
<button onclick="getLocation()">Get Current Location</button>
<p id="location">Location will be displayed here</p>
<script>
function getLocation() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
function onSuccess(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
document.getElementById('location').innerHTML =
`Latitude: ${latitude}<br>Longitude: ${longitude}`;
}
function onError(error) {
document.getElementById('location').innerHTML =
`Error: ${error.message}`;
}
</script>
</body>
</html>
5. Build and Run the Application
cordova build browser
cordova run browser