1var autocomplete; 2 3function getLatLongFromSelectedLocation() { 4 var place = autocomplete.getPlace(); 5 6 if (!place.geometry || !place.geometry.location) { 7 console.warn('No geometry for selected place'); 8 return; 9 } 10 11 jQuery('#hdn_latitude').val(place.geometry.location.lat()); 12 jQuery('#hdn_longitude').val(place.geometry.location.lng()); 13 14 var components_by_type = {}; 15 if (place.address_components) { 16 place.address_components.forEach(function(component) { 17 components_by_type[component.types[0]] = component; 18 }); 19 } 20} 21 22function locateClinic() { 23 jQuery('#clinicSearch').keydown(function (e) { 24 var LatLonEmpty = jQuery('#hdn_latitude').val() == "" && jQuery('#hdn_longitude').val() == ""; 25 if (e.key === "Enter" && LatLonEmpty) { 26 e.preventDefault(); 27 } else if (e.key === "Enter" && !LatLonEmpty) { 28 jQuery("#findClinic").submit(); 29 } 30 }); 31} 32 33function validateClinicSearch() { 34 var errorCounter = 0; 35 var LatLonEmpty = jQuery('#hdn_latitude').val() == "" && jQuery('#hdn_longitude').val() == ""; 36 37 if (LatLonEmpty) { 38 jQuery("#clinicSearch").addClass('clinicSearchValidationError'); 39 errorCounter++; 40 } else { 41 jQuery('#clinicSearch').removeClass('clinicSearchValidationError'); 42 } 43 return errorCounter; 44} 45 46jQuery(document).ready(function () { 47 // Create the script tag, set the appropriate attributes 48 var script = document.createElement('script'); 49 script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyC84Kqu7iPKmoMfRgxtTgRUcX3598Xs49c&loading=async&libraries=places&callback=initLocationSearch&v=weekly'; 50 script.async = true; 51 52 // Attach callback to the window object 53 window.initLocationSearch = function initLocationSearch() { 54 autocomplete = new google.maps.places.Autocomplete(document.getElementById('clinicSearch'), { 55 types: ['geocode'], 56 fields: ['place_id', 'geometry', 'formatted_address', 'name', 'address_components'] 57 }); 58 autocomplete.setComponentRestrictions({ 59 country: ['us'] 60 }); 61 autocomplete.addListener('place_changed', getLatLongFromSelectedLocation); 62 }; 63 64 // Append the script element to head 65 document.body.appendChild(script); 66 67 jQuery('#clinicSearchBtn').on('click', function () { 68 var errorCounter = validateClinicSearch(); 69 if (errorCounter > 0) { 70 return false; 71 } else { 72 jQuery("#findClinic").submit(); 73 } 74 }); 75 76 jQuery('#clinicSearch').on('change', function () { 77 if (jQuery('#clinicSearch').hasClass('clinicSearchValidationError')) { 78 jQuery('#clinicSearch').removeClass('clinicSearchValidationError'); 79 } 80 }); 81});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.