1/* ******************************** *\ 2 |* Create New Offer Map View *| 3 \* */ 4 5var map, geocoder, addressMarker; 6 7function initGMap(elem, zoom) { 8 var lat = $('#lat').val(); 9 var lng = $('#lng').val(); 10 lat = (typeof lat !== "undefined" && lat!== '') ? $('#lat').val() : 25.782324; 11 lng = (typeof lng !== "undefined" && lng !== '') ? $('#lng').val() : -80.2310801; 12// console.log('lat: ', lat); 13// console.log('lng: ', lng); 14 // set initial position 15 var defaultCenter = new google.maps.LatLng(lat, lng); 16 var myOptions = { 17 zoom: (typeof zoom !== 'undefined') ? zoom : 14, 18 center: defaultCenter, 19 mapTypeControl: false, 20 mapTypeControlOptions: { 21 style: google.maps.MapTypeControlStyle.DEFAULT, 22 mapTypeIds: [ 23 google.maps.MapTypeId.ROADMAP 24 ] 25 }, 26 zoomControl: true, 27 zoomControlOptions: { 28 style: google.maps.ZoomControlStyle.SMALL 29 } 30 }; 31 // default map options 32 map = new google.maps.Map(document.getElementById(elem), myOptions); 33 google.maps.event.addListenerOnce(map, 'idle', function () { 34 google.maps.event.trigger(map, 'resize'); 35 }); 36} 37 38function resize_map() { 39 google.maps.event.trigger(map, 'idle'); 40} 41 42 43function initGPlacesAPI(elem, showMarkers) { 44 var autocompleteOptions = {}; 45 try { 46 var placesAutocomplete = new google.maps.places.Autocomplete(document.getElementById(elem), autocompleteOptions); 47 google.maps.event.addListener(placesAutocomplete, 'place_changed', function () { 48 locateAddressOnGMap(elem, showMarkers); 49 }); 50 } catch (err) { 51 console.log(err); 52 } 53} 54 55function locateAddressOnGMap(elem, showMarkers) { 56 if (typeof addressMarker == "object") { 57 addressMarker.setMap(null); 58 } 59 if (typeof geocoder != "object") { 60 geocoder = new google.maps.Geocoder(); 61 } 62 var address = $('#' + elem).val(); 63 geocoder.geocode({'address': address}, function (results, status) { 64 if (status == google.maps.GeocoderStatus.OK) { 65 // and if everything is OK 66 // we will center map 67 setLatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()) 68 //console.log('result address components: ', results); 69 if ($('#postal_code').length > 0) { 70 for (var i in results) { 71 var address_component = results[i].address_components; 72 for (var j in address_component) { 73 //console.log('comp: ', address_component[j]); 74 var comp_types = address_component[j].types; 75 //console.log('compTypes: ', address_component[j].types); 76 77 if (comp_types[0] === "postal_code") { 78 var postal_code = address_component[j].long_name; 79 console.log('Postal Code: ', postal_code); 80 if ($('#postal_code').val() == "") { 81 $('#postal_code').val(postal_code); 82 } 83 } 84 } 85 } 86 } 87 //console.log('result: ', status); 88 var contentString = '<p>Current location.</p>'; 89 var infowindow = new google.maps.InfoWindow({ 90 content: contentString 91 }); 92 var addressLocation = results[0].geometry.location; 93 map.setCenter(addressLocation); 94 if (showMarkers) { 95 var draggable = false; 96 if ($('#user_lat').length > 0 && $('#user_lng').length > 0) { 97 draggable = true; 98 } 99 $('#user_lat').val(results[0].geometry.location.lat()); 100 $('#user_lng').val(results[0].geometry.location.lng()); 101 addressMarker = new google.maps.Marker({ 102 position: addressLocation, 103 map: map, 104 draggable: draggable, 105 title: results[0].formatted_address, 106 // icon: commonAssetUrl + 'images/marker.png' 107 }); 108 if (draggable) { 109 google.maps.event.addListener(addressMarker, 'dragend', function (event) { 110 $("#user_lat").val(this.getPosition().lat()); 111 $("#user_lng").val(this.getPosition().lng()); 112 }); 113 } 114 } 115 } 116 else if (status == google.maps.GeocoderStatus.ZERO_RESULTS) { 117// notify({ 118// title: "Information", 119// message: "Please enter an address", 120// type: "info" 121// }); 122 console.log('Please enter an address'); 123 $('#' + elem).focus(); 124 } 125 else { 126// notify({
127// title: "Error!!", 128// message: "Geocode was not successful for the following reason: \n" + status, 129// type: "error" 130// }); 131 console.error("Geocode was not successful for the following reason: \n" + status); 132 } 133 }); 134 135} 136 137function showMarker(lat, lng, title, draggable) { 138// console.log('show marker', title); 139// console.log('lat: ', lat); 140// console.log('lng: ', lng); 141 lat = (typeof lat !== 'undefined' && lat != '') ? lat : 30.3753; 142 lng = (typeof lat !== 'undefined' && lng != '') ? lng : 69.3451; 143 setLatLng(lat, lng); 144 draggable = (typeof draggable !== "undefined") ? draggable : true; 145 var position = new google.maps.LatLng(lat, lng); 146// console.log('Position : ', position); 147 map.setCenter(position); 148 var addressMarker = new google.maps.Marker({ 149 position: position, 150 draggable: draggable, 151 map: map, 152 title: title, 153 visible: true, 154 //icon: commonAssetUrl + 'images/marker.png' 155 }); 156 if (draggable) { 157 google.maps.event.addListener( 158 addressMarker, 159 'drag', 160 function () { 161 document.getElementById('lat').value = addressMarker.position.lat(); 162 document.getElementById('lng').value = addressMarker.position.lng(); 163 } 164 ); 165 } 166} 167 168function showMarkers(latLongs) { 169 //console.log('=> typeof: ',typeof latLongs); 170 if (typeof latLongs !== "undefined") { 171 for (var i in latLongs) { 172 showMarker(latLongs[i].lat, latLongs[i].lng, latLongs[i].title); 173 } 174 } 175} 176// for create new offer 177try { 178// initGMap('map_canvas'); 179} 180catch (err) { 181 console.log(err); 182} 183 184// initGPlacesAPI('map_address', true); 185 186 187function map_show() { 188 initGMap('map_canvas'); 189 initGPlacesAPI('map_address', true); 190 locateAddressOnGMap('map_address', true); 191} 192 193function getCurrentLocation() { 194 // element exists, check if navigator is available in the browser 195 if (navigator.geolocation) { 196 197 // yes, browser supports geolocation, get current location 198 navigator.geolocation.getCurrentPosition(function (position) { 199 // show marker and set current location as map center 200 var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 201 addMarker(latLng, '<b>Your current location<b>', true); 202 setLocation(latLng.lat(), latLng.lng()); 203 }, function () { 204 console.warn("ROZEE.PK - Geolocation service failed! Unable to get your current position."); 205 // set default center location 206 map.setCenter(new google.maps.LatLng(25.782324, -80.2310801)); 207 }); 208 } 209 else { 210 // Browser doesn't support Geolocation 211 console.warn("ROZEE.PK - Your browser does not support geolocation."); 212 } 213} 214 215 216function addMarker(latLng, content, setCenter) { 217 setLatLng(latLng.lat(), latLng.lng()) 218 // create info window object 219 var infowindow = new google.maps.InfoWindow(); 220 infowindow.setContent(content); 221 try { 222 if (setCenter == true) { 223 map.setCenter(latLng); 224 } 225 } catch (err) { 226 console.log(err); 227 } 228 // and then - add new custom marker 229 var options = { 230 position: latLng, 231 map: map, 232 draggable: false 233 }; 234 // options.icon = commonAssetUrl + 'images/tow_marker.png'; // for custom marker icon 235 var mark = new google.maps.Marker(options); 236 mark.addListener('click', function () { 237 infowindow.open(map, mark); 238 }); 239} 240 241function setLatLng(lat, lng) { 242 $('#lat').val(lat); 243 $('#lng').val(lng); 244} 245 246 247function setLocation(lat, lng) { 248 249 var geocoder; 250 geocoder = new google.maps.Geocoder(); 251 var latlng = new google.maps.LatLng(lat, lng); 252 253 geocoder.geocode( 254 {'latLng': latlng}, 255 function (results, status) { 256 var response = results; 257 //console.log('Result: ', results); 258 // console.log('Address Comments: ', results[0].address_components); 259 if (status == google.maps.GeocoderStatus.OK) { 260 if (results[0]) { 261 var data = results[0].address_components; 262 for (var i in data) { 263 $('#country option').filter(function () { 264 if ($(this).text() == data[i].short_name) { 265 $('#country').val($(this).val()); 266 //$('.selectpicker').selectpicker('refresh'); 267 } 268 }); 269 $('#cities option').filter(function () { 270 if ($(this).text() == data[i].short_name) { 271 //console.log('City: ', $(this).val()); 272 $('#cities').val($(this).val()).trigger('chosen:updated'); 273 //$('.selectpicker').selectpicker('refresh'); 274 getCityAreas(); //Fetching Areas Regarding City 275 276 } 277 }); 278 279 } 280 281 //console.log('Again RESUL=> ', response); 282 var googleAreas = []; 283 for (var j in response) { 284 //console.log('Result -> ' + j, response[j]); 285 var data = response[j].address_components; 286 //console.log('Data Address Componenets: ' + j + '=> ', data); 287 for (var k in data) { 288 289 //console.log('area name: ', data[k].short_name); 290 var areaName = data[k].short_name; 291 googleAreas.push(areaName); // Orignal Name 292 areaNameArr = areaName.split(' '); 293 //console.log(' Area Name Array: ', areaNameArr); 294 for (var l in areaNameArr) { 295 areaNameArr[l] = areaNameArr[l].replace('III', '3'); 296 areaNameArr[l] = areaNameArr[l].replace('II', '2'); 297 areaNameArr[l] = areaNameArr[l].replace('I', '1'); 298 areaNameArr[l] = areaNameArr[l].replace('V', '5'); 299 areaNameArr[l] = areaNameArr[l].replace('IV', '4'); 300 } 301 //console.log(' New Area Name Array: ', areaNameArr); 302 areaName = areaNameArr.join(' '); 303 googleAreas.push(areaName); // Replaced New Name 304 } 305 } 306 //console.log(' Your Google Areas Are following: ', googleAreas); 307 //match area from given array 308 makeSelectedAreas(googleAreas); 309 310 } 311 else { 312 console.error("Rozee Error:- address not found"); 313 } 314 } 315 else { 316 console.error("Rozee Error:- Geocoder failed due to: " + status); 317 } 318 } 319 ); 320} 321 322function makeSelectedAreas(google_areas) { 323 324 //console.log(' Area Div=> ', $('#areas').val()); 325 if (typeof $('#areas').val() === 'undefined') { 326 setTimeout(function () { 327 //console.warn(' Google Areas ', google_areas); 328 for (var i in google_areas) { 329 var areaName = google_areas[i]; 330 $('#areas option').filter(function () { 331 //console.log('+========> Final Area => ', areaName); 332 if ($(this).text() == areaName) { 333 $('#areas').val($(this).val()); 334 // $('.selectpicker').selectpicker('refresh'); 335 } 336 }); 337 } 338 339 }, 1500); 340 } else { 341 var areaName = google_areas[i]; 342 $('#areas option').filter(function () { 343 //console.log('+========> Final Area => ', areaName); 344 if ($(this).text() == areaName) { 345 $('#areas').val($(this).val()); 346 //$('.selectpicker').selectpicker('refresh'); 347 } 348 }); 349 } 350}
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.