1// this is for Firefox mainly - if we get to w3c geolocation and permission 2// has not been granted to use location, we need to error out 3var timerId = window.setInterval(timedout, 10000); 4var locChanged = false; 5var geo_info = new Object(); 6function timedout() { 7 set_user_location(); //just serve the map without lat/lon 8} 9 10function w3c_geolocate(callback) { 11 // Last but not least, try W3C Geolocation method (Preferred) 12 if(navigator.geolocation) { 13 navigator.geolocation.getCurrentPosition(function(position) { 14 var latlng = [position.coords.latitude, position.coords.longitude]; 15 callback(latlng); 16 }, function(error) { 17 set_user_location(); 18 },{timeout:10000}); 19 } else { 20 // Browser doesn't support Geolocation 21 set_user_location(); //just serve the map without lat/lon 22 } 23} 24 25function google_geo_by_address(address, callback) { 26 geocoder = new google.maps.Geocoder(); 27 var locinfo = new Object(); 28 geocoder.geocode( {'address': address }, function(results, status) { 29 if(status == "OK") { 30 locinfo['default_lat'] = ""+results[0].geometry.location.lat(); 31 locinfo['default_lon'] = ""+results[0].geometry.location.lng(); 32 locinfo['default_locname'] = ""+results[0].formatted_address; 33 var place_names = new Array(); 34 place_names = locinfo['default_locname'].split(","); 35 var pnl = place_names.length; 36 var country_name = $.trim(place_names[pnl - 1]); 37 locinfo['default_country'] = ""+country_lu[country_name]; 38 } 39 callback(locinfo); 40 }); 41} 42 43function google_geo_by_ll(lat, lon, callback) { 44 if(!lat || !lon) { 45 w3c_geolocate(); 46 } 47 geocoder = new google.maps.Geocoder(); 48 var latlng = new google.maps.LatLng(lat, lon); 49 var locinfo = new Object(); 50 geocoder.geocode( {'latLng': latlng }, function(results, status) { 51 if(status == "OK") { 52 locinfo['default_lat'] = lat; 53 locinfo['default_lon'] = lon; 54 locinfo['default_locname'] = results[0].formatted_address; 55 var place_names = new Array(); 56 place_names = locinfo['default_locname'].split(","); 57 var pnl = place_names.length; 58 var country_name = $.trim(place_names[pnl - 1]); 59 locinfo['default_country'] = country_lu[country_name]; 60 } 61 callback(locinfo); 62 }); 63} 64 65// this is always called on pageload, then need to serve_map for first time 66function set_user_location(loc_info, hmu_id, preset_id, set_hm_cookie) { 67 // sometimes geo_info is not set, like if the user didn't accept geolocation 68 if(typeof(loc_info) == "undefined") { 69 geo_info['default_lat'] = worldlat; 70 geo_info['default_lon'] = worldlon; 71 geo_info['zoom_level'] = worldzoom; 72 geolocation = false; 73 } else { 74 geo_info = loc_info; // set this so it can be used globally 75 } 76 // allow for passing of lat/lon in the query string 77 if(typeof(passed_params['latlon']) != "undefined") { 78 var llarr = passed_params['latlon'].split(","); 79 geo_info['zoom_lat'] = llarr[0]; 80 geo_info['zoom_lon'] = llarr[1]; 81 geo_info['zoom_level'] = parseInt(llarr[2]); 82 passed_loc = true; 83 } 84 // set the geo_info to default if not set 85 geo_info['default_radius'] = geo_info['default_radius'] ? geo_info['default_radius'] : 50; 86 if(set_hm_cookie) { 87 var user_info = new Object(); 88 user_info['hmu_id'] = hmu_id; 89 user_info['default_location'] = geo_info['default_lat']+","+geo_info['default_lon']; 90 user_info['default_locname'] = geo_info['default_locname']; 91 user_info['default_radius'] = geo_info['default_radius']; 92 user_info['default_country'] = geo_info['default_country']; 93 $.ajax({ url: "../authUser.php", dataType: 'json', data: user_info, 94 success: function(jsonData) { 95 //console.log(jsonData); 96 } 97 }); 98 } 99 // geo_info comes in from google_geo_by_ll as an object: lat, lon, locname 100 if(geolocation) { 101 // by default, show local info 102 //$('#radius_change').val(geo_info['default_radius']); 103 $("#locations_dropdown label:first").html('Your Location<span id="locname">: '+geo_info['default_locname']+'</span>'); 104 // sometimes zoom is passed in 105 geo_info['zoom_level'] = geo_info['zoom_level'] ? geo_info['zoom_level'] : localzoom; 106 } else { 107 $("#currentlocation").parent().hide(); 108 } 109 110 if(locChanged) { 111 return geo_info; 112 } 113 114 serve_map(hmu_id, preset_id); 115
116 // hide flucast site link if user is not in US 117 if(location_info['default_country'] != 106) { 118 $('#flucastsite').hide(); 119 } 120 var state = location_info['default_locname']; 121 /* $('#goviral').hide(); 122 if((state.indexOf('MA') !== -1) || (state.indexOf('NY') !== -1)) { 123 $('#goviral').show(); 124 }*/ 125}
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.