Beat the COVID 19 lock-down - grab a Boredom Busting Bargain today
04/04/2020 10:27 pm With the likely hood that this COVID 19 lock down will will continue for several months, GM Frost, the Masters and all the
function clearValidity($this){
const $parent = jQuery($this).closest('.piotnetforms-field-subgroup');
const $firstOption = $parent.find('.piotnetforms-field-option input');
$firstOption.each(function(){
jQuery(this).setCustomValidity('');
});
}
function piotnetformsAddressAutocompleteInitMap() {
var inputs = document.querySelectorAll('');
inputs.forEach(function(el, index, array){
var autocomplete = new google.maps.places.Autocomplete(el);
var country = el.getAttribute('data-piotnetforms-address-autocomplete-country');
var map_lat = el.getAttribute('data-piotnetforms-google-maps-lat');
var map_lng = el.getAttribute('data-piotnetforms-google-maps-lng');
var zoom = el.getAttribute('data-piotnetforms-google-maps-zoom');
if(country == 'All') {
autocomplete.setComponentRestrictions({'country': });
} else {
autocomplete.setComponentRestrictions({'country': country});
}
var $mapSelector = el.closest('.piotnetforms-fields-wrapper').querySelectorAll('');
if($mapSelector.length>0) {
var myLatLng = { lat: parseFloat(map_lat), lng: parseFloat(map_lng) };
var map_zoom = parseInt(zoom);
var map = new google.maps.Map($mapSelector, {
center: myLatLng,
// center: {lat: -33.8688, lng: 151.2195},
zoom: map_zoom
});
var infowindow = new google.maps.InfoWindow();
var infowindowContent = el.closest('.piotnetforms-fields-wrapper').querySelectorAll('.infowindow-content');
infowindow.setContent(infowindowContent);
var marker = new google.maps.Marker({
map: map,
anchorPoint: new google.maps.Point(0, -29)
});
autocomplete.addListener('place_changed', function() {
infowindow.close();
marker.setVisible(false);
var place = autocomplete.getPlace();
if (!place.geometry) {
// User entered the name of a Place that was not suggested and
// pressed the Enter key, or the Place Details request failed.
window.alert("No details available for input: '" + place.name + "'");
return;
}
// If the place has a geometry, then present it on a map.
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17); // Why 17? Because it looks good.
}
marker.setPosition(place.geometry.location);
marker.setVisible(true);
var address = '';
if (place.address_components) {
address = [
(place.address_components.short_name || ''),
(place.address_components.short_name || ''),
(place.address_components.short_name || '')
].join(' ');
}
infowindowContent.children.src = place.icon;
infowindowContent.children.textContent = place.name;
infowindowContent.children.textContent = address;
infowindow.open(map, marker);
});
}
autocomplete.addListener('place_changed', function() {
var place = autocomplete.getPlace();
el.setAttribute('data-piotnetforms-google-maps-lat', place.geometry.location.lat());
el.setAttribute('data-piotnetforms-google-maps-lng', place.geometry.location.lng());
el.setAttribute('data-piotnetforms-google-maps-formatted-address', place.formatted_address);
el.setAttribute('data-piotnetforms-google-maps-zoom', '17');
var $distanceCalculation = document.querySelectorAll('');
$distanceCalculation.forEach(function(el, index, array){
if (el.getAttribute('data-piotnetforms-calculated-fields-distance-calculation-from') !== null) {
var origin = el.getAttribute('data-piotnetforms-calculated-fields-distance-calculation-from');
} else {
var $origin = document.getElementById( el.getAttribute('data-piotnetforms-calculated-fields-distance-calculation-from-field-shortcode').replace('','') );
var origin = $origin.getAttribute('data-piotnetforms-google-maps-formatted-address');
}
if (el.getAttribute('data-piotnetforms-calculated-fields-distance-calculation-to') !== null) {
var destination = el.getAttribute('data-piotnetforms-calculated-fields-distance-calculation-to');
} else {
$destination = document.getElementById( el.getAttribute('data-piotnetforms-calculated-fields-distance-calculation-to-field-shortcode').replace('','') );
var destination = $destination.getAttribute('data-piotnetforms-google-maps-formatted-address');
}
if (origin != '' && destination != '') {
var distanceUnit = el.getAttribute('data-piotnetforms-calculated-fields-distance-calculation-unit');
calculateDistance(origin, destination, el.closest('.piotnetforms-field-container').querySelector('.piotnetforms-calculated-fields-form__value'), distanceUnit, el);
}
});
});
});
}
// calculate distance
function calculateDistance(origin, destination, $el, distanceUnit, $input) {
if (origin != '' && destination != '') {
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: ,
destinations: ,
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.IMPERIAL, // miles and feet.
// unitSystem: google.maps.UnitSystem.metric, // kilometers and meters.
avoidHighways: false,
avoidTolls: false
}, function (response, status) {
if (status != google.maps.DistanceMatrixStatus.OK) {
// console.log(err);
} else {
var origin = response.originAddresses;
var destination = response.destinationAddresses;
if (response.rows.status === "ZERO_RESULTS") {
// console.log("Better get on a plane. There are no roads between " + origin + " and " + destination);
} else {
var distance = response.rows.distance;
var duration = response.rows.duration;
// console.log(response.rows.distance);
var distance_in_kilo = distance.value / 1000; // the kilom
var distance_in_mile = distance.value / 1609.34; // the mile
var duration_text = duration.text;
var duration_value = duration.value;
var event = new Event("change");
if (distanceUnit == 'km') {
$el.innerHTML = distance_in_kilo.toFixed(2);
$input.value = distance_in_kilo.toFixed(2);
jQuery($input).change();
} else {
$el.innerHTML = distance_in_mile.toFixed(2);
$input.value = distance_in_mile.toFixed(2);
jQuery($input).change();
}
}
}
});
}
}
// get distance results
function callback(response, status) {
if (status != google.maps.DistanceMatrixStatus.OK) {
console.log(err);
} else {
var origin = response.originAddresses;
var destination = response.destinationAddresses;
if (response.rows.status === "ZERO_RESULTS") {
console.log("Better get on a plane. There are no roads between " + origin + " and " + destination);
} else {
var distance = response.rows.distance;
var duration = response.rows.duration;
console.log(response.rows.distance);
var distance_in_kilo = distance.value / 1000; // the kilom
var distance_in_mile = distance.value / 1609.34; // the mile
var duration_text = duration.text;
var duration_value = duration.value;
console.log(distance_in_mile.toFixed(2) + 'miles');
return distance_in_kilo.toFixed(2);
// $('#duration_text').text(duration_text);
// $('#duration_value').text(duration_value);
// $('#from').text(origin);
// $('#to').text(destination);
}
}
}
document.addEventListener( 'elementor/popup/show', function(event, id, instance){
piotnetformsAddressAutocompleteInitMap();
} );
Read Article…