PageSourceSearch

https://online.aromaindian.com.au/js/search-location-topbar-asset.js?v=1783000287

js aromaindian.com.au collected 2026-09-27 01:10:32 UTC 6,059 bytes, 157 lines download raw bytes

1var placeSearchTopbar, autocompleteTopbar;
2
3var componentFormAuto = {
4  street_number: 'short_name',
5  route: 'long_name',
6  locality: 'long_name',
7  administrative_area_level_1: 'long_name',
8  country: 'long_name',
9  postal_code: 'short_name'
10};
11
12function initAutocompleteTopbar() {
13  // Create the autocomplete object, restricting the search predictions to
14  // geographical location types.
15  autocompleteTopbar = new google.maps.places.Autocomplete(
16      document.getElementById('autocompleteTopbar'), {types: ['geocode'],componentRestrictions: {country:RESTAURANT_CONFIG.country_short_name}});
17
18  // Avoid paying for data that you don't need by restricting the set of
19  // place fields that are returned to just the address components.
20  autocompleteTopbar.setFields(['address_component', 'geometry']);
21
22  // When the user selects an address from the drop-down, populate the
23  // address fields in the form.
24  autocompleteTopbar.addListener('place_changed', topbarValidateAddress);
25
26  if (navigator.geolocation) 
27    {
28      navigator.geolocation.getCurrentPosition(function(position)
29      {
30        var pos = {
31          lat: position.coords.latitude,
32          lng: position.coords.longitude
33        };
34
35        latitude=position.coords.latitude;
36        longitude=position.coords.longitude;      
37        var latlng = latitude+', '+longitude;   
38        var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng="+ latlng +"&key=AIzaSyC1a6NYpboLW8iNOoa-cybNMe5cH-sErVM";
39                
40        $.getJSON(url, function (data) {
41        
42          for(var i=0;i<data.results.length;i++) {
43            var address = data.results[0].formatted_address;
44            var currCityName=address;
45            var currLatitude=latitude;
46            var currLongitude=longitude;
47          }
48          $("#autocompleteTopbar").val(address);
49          topbarValidateAddress(currLatitude, currLongitude);
50
51          // if (data.results[0].address_components) {
52          // autoadd = [
53          // (data.results[0].address_components[0] && data.results[0].address_components[0].short_name || ''),
54          // (data.results[0].address_components[1] && data.results[0].address_components[1].short_name || ''),
55          // (data.results[0].address_components[2] && data.results[0].address_components[2].short_name || ''),
56          // (data.results[0].address_components[3] && data.results[0].address_components[3].short_name || ''),
57          // (data.results[0].address_components[4] && data.results[0].address_components[4].short_name || ''),
58          // (data.results[0].address_components[5] && data.results[0].address_components[5].short_name || '')
59          // ].join(' ');
60          // }
61        
62          // for (var i = 0; i < data.results[0].address_components.length; i++) {
63          //   var addressType = data.results[0].address_components[i].types[0];
64          //   if (componentForm[addressType]) {
65          //     var val = data.results[0].address_components[i][componentForm[addressType]];
66          //     document.getElementById(addressType).value = val;
67          //   }
68          // }
69        });
70
71      }, function() {
72      });
73    } 
74    else 
75    {
76      console.log('Error Getting Location');
77    }
78}
79
80function topbarValidateAddress(currLat=null, currLong=null) {
81  // Get the place details from the autocomplete object.
82  if (currLat == null && currLong == null) {
83      var place = autocompleteTopbar.getPlace();
84
85      var lat=place.geometry.location.lat();
86      var lng=place.geometry.location.lng();
87  } else {
88      var lat = currLat;
89      var lng = currLong;
90  }
91
92  if (findDistance(parseFloat(RESTAURANT_CONFIG.lat), parseFloat(RESTAURANT_CONFIG.long), parseFloat(lat), parseFloat(lng), "K") <= parseFloat(RESTAURANT_CONFIG.delivery_radius)) {
93      $("#autocompleteTopbar")
94          .attr('data-original-title', "Delivery available at this address :)")
95          .tooltip({placement: 'right', delay: {hide: 200}});
96      $("#autocompleteTopbar").css("border", "solid 2px green");
97  } else {
98      $("#autocompleteTopbar")
99          .attr('data-original-title', "Delivery not available at this address :(")
100          .tooltip({placement: 'right', delay: {hide: 200}});
101      $("#autocompleteTopbar").css("border", "solid 2px red");
102  }
103  
104  // $('#latitude').val(place.geometry.location.lat());
105  // $('#longitude').val(place.geometry.location.lng());
106
107}
108
109// Bias the autocomplete object to the user's geographical location,
110// as supplied by the browser's 'navigator.geolocation' object.
111function geolocate() {
112  if (navigator.geolocation) {
113    navigator.geolocation.getCurrentPosition(function(position) {
114      var geolocation = {
115        lat: position.coords.latitude,
116        lng: position.coords.longitude
117      };
118      var circle = new google.maps.Circle(
119          {center: geolocation, radius: position.coords.accuracy});
120      autocompleteTopbar.setBounds(circle.getBounds());
121    });
122  }
123}
124
125/**
126 * Distance
127 *    lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) 
128 *    lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) 
129 *    unit = the unit you desire for results
130 *           where: 'M' is statute miles (default)                        
131 *                  'K' is kilometers                                     
132 *                  'N' is nautical miles    
133 */
134function findDistance(lat1, lon1, lat2, lon2, unit) {
135  if ((lat1 == lat2) && (lon1 == lon2)) {
136    return 0;
137  }
138  else {
139    var radlat1 = Math.PI * lat1/180;
140    var radlat2 = Math.PI * lat2/180;
141    var theta = lon1-lon2;
142    var radtheta = Math.PI * theta/180;
143    var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
144    if (dist > 1) {
145      dist = 1;
146    }
147    dist = Math.acos(dist);
148    dist = dist * 180/Math.PI;
149    dist = dist * 60 * 1.1515;
150    if (unit=="K") { dist = dist * 1.609344 }
151    if (unit=="N") { dist = dist * 0.8684 }
152    console.log("Distance====:", dist);
153    return dist;
154  }
155}
156
157// initAutocompleteTopbar();

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.