Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function CachedLocation(loc, cellInfo, wifiList) {
- this.location = loc;
- this.cellInfo = cellInfo;
- this.wifiList = wifiList;
- }
- CachedLocation.prototype = {
- constructor: CachedLocation,
- isGeoip: function() {
- return !this.cellInfo && !this.wifiList;
- },
- isCellAndWifi: function() {
- return this.cellInfo && this.wifiList;
- },
- isCellOnly: function() {
- return this.cellInfo && !this.wifiList;
- },
- isWifiOnly: function() {
- return this.wifiList && !this.cellInfo;
- },
- //-> if 50% of the SSIDS match
- isWifiApproxEqual: function(wifiList) {
- if (!this.wifiList)
- return false;
- },
- //if fields match and signal is within ?% (who can answer this)
- isCellApproxEqual: function(cellInfo) {
- if (!this.cellInfo)
- return false;
- }
- };
- var gCachedLocation;
- // return null if not better
- function getCachedLocIfBetter(newCell, newWifiList)
- {
- if (!gCachedLocation)
- return null;
- // if new request has both cell and wifi, and old is just cell
- if (gCachedLocation.isCellOnly() && newCell && newWIfiList) {
- return null;
- }
- // if new is geoip request
- if (!newCell && !newWifiList) {
- return gOldLocation.location;
- }
- var hasEqualCells = false;
- if (newCell) {
- hasEqualCells = gCachedLocation.isCellsApproxEqual(newCell);
- }
- var hasEqualWifis = false;
- if (newWifiList) {
- hasEqualWifis = gCachedLocation.isWifiApproxEqual(newWifiList);
- }
- if (gCachedLocation.isCellOnly()) {
- if (hasEqualCells)
- return gOldLocation.location;
- }
- else if (gCacheLocation.isCellAndWifi()) {
- if ((hasEqualCells && hasEqualWifis) ||
- (!newWifiList && hasEqualCells) ||
- (!newCell && hasEqualWifis)
- {
- return gOldLocation.location;
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement