Set Delivery Location
Or
Device Location is turned off
TURN ON
Show Map
Modal Header
Some text in the modal.
>
Oops!
Hey, the nearest KFC store to your location is temporarily closed for delivery. Do you want to do a takeaway order instead.
'+brlocations[i][3]+'
'); brinfowindow.open(brmap, brmarker); } })(brmarker, i)); } //nearest branch 1 $('#nearest_stores').html("" + ''); //nearest branch 2 $('#nearest_stores').append("" + ''); } console.log(whichPolygon); }, 1000); } function isDelivery() { var dsale_type = document.getElementById('kfc_sale_type').value; //alert(whichPolygon.length); if (whichPolygon.length > 0) { if(dsale_type == 'delivery') return true; } } //calculates distance between two points in km's function calculateDistance(pointer_1, pointer_2) { var dist = (google.maps.geometry.spherical.computeDistanceBetween(pointer_1, pointer_2) / 1000).toFixed(2); return parseFloat(dist); } function findPolygon(polygon) { return google.maps.geometry.poly.containsLocation(new google.maps.LatLng(wPos.lat, wPos.lng), polygon) } $(document).on("click", ".takeaway-to-active", function () { document.getElementById('kfc_sale_type').value = 'take_away'; $('.location-section').css('display','block'); $('.nearest-store-address').css('display', 'block'); //alert(); //checkPolygon(); //markerUpdate(geocoder, marker, infowindow, triangleCoords, branchDetailsArr, allPoly); }); /* * Find Current Location */ $('#autoDetect').on('click',function() { // If geolocation enabled if (navigator.geolocation) { //Get current position navigator.geolocation.getCurrentPosition(function (position) { var lat, long, address, resultArray, citi; //console.log('Current Location Found'); lat = position.coords.latitude; long = position.coords.longitude; var pos = { lat: position.coords.latitude, lng: position.coords.longitude }; marker.setPosition(pos); //marker.setVisible(true); var geocoder = new google.maps.Geocoder(); geocoder.geocode({latLng: pos}, function (result, status) { if ('OK' === status) { // This line can also be written like if ( status == google.maps.GeocoderStatus.OK ) { address = result[0].formatted_address; resultArray = result[0].address_components; // Get the city and set the city input value to the one selected /*for (var i = 0; i < resultArray.length; i++) { if (resultArray[i].types[0] && 'administrative_area_level_2' === resultArray[i].types[0]) { citi = resultArray[i].long_name; console.log(citi); city.value = citi; } }*/ addressEl.value = address; latEl.value = lat; longEl.value = long; wPos.lat = lat; wPos.lng = long; var distanceArr = []; for (var barea in outlets) { var bareas = outlets[barea]; var location1 = new google.maps.LatLng(lat, long); var location2 = new google.maps.LatLng(bareas.lat, bareas.lng); distanceArr.push(calculateDistance(location1, location2)); } console.log('Origin', distanceArr); var firstMinVal = Math.min(...Object.values(distanceArr)) var firstFromKey = Object.keys(distanceArr).find(key => distanceArr[key] === firstMinVal) console.log('FKey', firstFromKey); console.log('FValue', firstMinVal); minDist1 = firstMinVal; nearestBranch1 = outlets[firstFromKey]; console.log('B1', nearestBranch1); distanceArr.splice(firstFromKey, 1); //console.log('Remain', distanceArr); var secondMinVal = Math.min(...Object.values(distanceArr)) var secondFromKey = Object.keys(distanceArr).find(key => distanceArr[key] === secondMinVal) console.log('SKey', secondFromKey); console.log('SValue', secondMinVal); minDist2 = secondMinVal; nearestBranch2 = outlets[secondFromKey]; console.log('B2', nearestBranch2); checkPolygon() } else { console.log('Geocode was not successful for the following reason: ' + status); } // Closes the previous info window if it already exists if (infoWindow) { infoWindow.close(); } /** * Creates the info Window at the top of the marker */ infoWindow = new google.maps.InfoWindow({ content: address }); infoWindow.open(map, marker); }); }); } }); /* * Search */ autocomplete.addListener('place_changed', function() { var lat, long, address, resultArray, citi; //console.log( 'i am searched' ); lat = marker.getPosition().lat(); long = marker.getPosition().lng(); var geocoder = new google.maps.Geocoder(); var place = autocomplete.getPlace(); console.log(place); // If the place has a geometry, then present it on a map. if (place.geometry.viewport) { // map.fitBounds(place.geometry.viewport); var latitude = place.geometry.location.lat(); var longitude = place.geometry.location.lng(); } else { map.setCenter(place.geometry.location); map.setZoom(17); // Why 17? Because it looks good. } //marker.setPosition(place.geometry.location); //marker.setVisible(true); var pos = { lat: latitude, lng: longitude }; console.log(pos); wPos.lat = latitude; wPos.lng = longitude; //console.log(latitude); //console.log(longitude); var distanceArr = []; for (var barea in outlets) { var bareas = outlets[barea]; var location1 = new google.maps.LatLng(latitude, longitude); var location2 = new google.maps.LatLng(bareas.lat, bareas.lng); distanceArr.push(calculateDistance(location1, location2)); } console.log('Origin', distanceArr); var firstMinVal = Math.min(...Object.values(distanceArr)) var firstFromKey = Object.keys(distanceArr).find(key => distanceArr[key] === firstMinVal) console.log('FKey', firstFromKey); console.log('FValue', firstMinVal); minDist1 = firstMinVal; nearestBranch1 = outlets[firstFromKey]; console.log('B1', nearestBranch1); distanceArr.splice(firstFromKey, 1); //console.log('Remain', distanceArr); var secondMinVal = Math.min(...Object.values(distanceArr)) var secondFromKey = Object.keys(distanceArr).find(key => distanceArr[key] === secondMinVal) console.log('SKey', secondFromKey); console.log('SValue', secondMinVal); minDist2 = secondMinVal; nearestBranch2 = outlets[secondFromKey]; console.log('B2', nearestBranch2); geocoder.geocode( { latLng: pos }, function ( result, status ) { if ( 'OK' === status ) { // This line can also be written like if ( status == google.maps.GeocoderStatus.OK ) { address = result[0].formatted_address; resultArray = result[0].address_components; // Get the city and set the city input value to the one selected /*for( var i = 0; i < resultArray.length; i++ ) { if ( resultArray[ i ].types[0] && 'administrative_area_level_2' === resultArray[ i ].types[0] ) { citi = resultArray[ i ].long_name; console.log( citi ); city.value = citi; } }*/ addressEl.value = address; latEl.value = lat; longEl.value = long; checkPolygon () } else { console.log( 'Geocode was not successful for the following reason: ' + status ); } // Closes the previous info window if it already exists if ( infoWindow ) { infoWindow.close(); } /** * Creates the info Window at the top of the marker */ infoWindow = new google.maps.InfoWindow({ content: address }); infoWindow.open( map, marker ); } ); }); /* * Finds the new position of the marker when the marker is dragged. */ google.maps.event.addListener( marker, "dragend", function ( event ) { var lat, long, address, resultArray, citi; //console.log( 'i am dragged' ); lat = marker.getPosition().lat(); long = marker.getPosition().lng(); var geocoder = new google.maps.Geocoder(); geocoder.geocode( { latLng: marker.getPosition() }, function ( result, status ) { if ( 'OK' === status ) { // This line can also be written like if ( status == google.maps.GeocoderStatus.OK ) { address = result[0].formatted_address; resultArray = result[0].address_components; // Get the city and set the city input value to the one selected for( var i = 0; i < resultArray.length; i++ ) { if ( resultArray[ i ].types[0] && 'administrative_area_level_2' === resultArray[ i ].types[0] ) { citi = resultArray[ i ].long_name; console.log( citi ); city.value = citi; } } addressEl.value = address; latEl.value = lat; longEl.value = long; wPos.lat = lat; wPos.lng = long; checkPolygon () } else { console.log( 'Geocode was not successful for the following reason: ' + status ); } // Closes the previous info window if it already exists if ( infoWindow ) { infoWindow.close(); } /** * Creates the info Window at the top of the marker */ infoWindow = new google.maps.InfoWindow({ content: address }); infoWindow.open( map, marker ); } ); }); }); function emptyAll() { //alert(); $('.input-group p').empty(); $('.nearest-store-address.location-section').css('display', 'none'); document.getElementById('searchInput').value = ''; $('#confirm-my-location').css('display', 'none'); $('#confirm-location-section').css('display', 'none'); $('#takeway-msg').css('display', 'none'); $('#your-location-show').css('display', 'none'); $('#map_pointer').css('display', 'none'); } function proceedMenu(branch){ document.getElementById('selectedBranch').value = branch; document.getElementById('proceedMenuBar').style.display = "block"; } function sessionSet(slug, branch) { //var branch = ''; if (branch == '') branch = jQuery('#selectedBranch').val(); var lat = jQuery('#lat').val(); var lng = jQuery('#lng').val(); var sale_type = jQuery('#kfc_sale_type').val(); var location = jQuery('#location').val(); var previous_url = jQuery('#previous_url').val(); var url = "https://kfcbd.com/menu/locationset"; //alert(branch); if (branch == '') alert('Please select branch'); else { //alert('ASI'); jQuery('#btn_submit').html(''); jQuery('.nearest-store-address.location-section').css('display', 'none'); jQuery.ajaxSetup({ headers: { 'X-CSRF-TOKEN': jQuery('meta[name="csrf-token"]').attr('content') } }); jQuery.ajax({ url: url, method: 'post', data: { branch: branch, location: location, sale_type: sale_type, lat: lat, lng: lng }, success: function(result){ window.location.href = "https://kfcbd.com"; //console.log(result); } }); } }