| Server IP : 103.234.187.230 / Your IP : 216.73.216.216 Web Server : Apache System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/b2bzend/ |
Upload File : |
<!DOCTYPE html>
<html>
<head>
<title>Google Maps API Example</title>
<style>
#map {
height: 400px;
width: 100%;
}
</style>
</head>
<body>
<h3>My Google Maps Example</h3>
<input type="text" name="google_location" class="form-control" id="google_location" placeholder="Enter Google Location" value="">
<!-- Load the Google Maps script and call initMap after the HTML has loaded -->
<script src='https://maps.googleapis.com/maps/api/js?key=AIzaSyDMc-dzKR8QpYdNtcux9ZZ-Lb_ECc4cfAc&libraries=places'></script>
<script>
let autocomplete;
function initAutocomplete() {
// Initialize the autocomplete object
autocomplete = new google.maps.places.Autocomplete(
document.getElementById('google_location'), {
// document.getElementById('autocomplete'), {
types: ['geocode']
}
);
// Set the function to run when a location is selected
autocomplete.addListener('place_changed', fillInAddress);
}
function fillInAddress() {
// Get the place details from the autocomplete object
const place = autocomplete.getPlace();
// Fetch latitude and longitude
const latitude = place.geometry.location.lat();
const longitude = place.geometry.location.lng();
// Set the values in the input fields
document.getElementById('start_lat').value = latitude;
document.getElementById('start_long').value = longitude;
}
// Bias the autocomplete object to user's geolocation
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
const geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
const circle = new google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
autocomplete.setBounds(circle.getBounds());
});
}
}
// Initialize the autocomplete function when the page is loaded
document.addEventListener("DOMContentLoaded", function() {
initAutocomplete();
});
</script>
</body>
</html>