草庐IT

working-with-geolocations

全部标签

javascript - 链式 jQuery promises with abort

我目前正在编写API代码,其中包含多层深度的$.ajax()调用。一个要求是用户必须能够取消任何请求(例如,如果它花费的时间太长)。通常这是通过一些简单的事情来完成的,比如:varjqXHR=$.ajax(..);$(mycancelitem).click(function(){jqXHR.abort();});但是我的代码看起来更像这样:functionmyapicall(){varjqxhr=$.ajax(…);varprms=def.then(function(result){//modifytheresultherereturnresult+5;});returnprms;}这

javascript - NodeJS + 套接字.io : simple Client/Server example not working

我正在使用NodeJSv0.4.8和最新版本的socket.ionpminstallsocket.io在Ubuntu上:Linuxmars2.6.38-8-generic#42-UbuntuSMPMonApr1103:31:50UTC2011i686i686i386GNU/Linux不幸的是,以下代码不会产生任何输出,无论是在客户端还是在服务器端。有人知道吗?服务器端varhttp=require('http'),io=require('socket.io'),fs=require('fs'),sys=require('sys');respcont=fs.readFileSync('t

javascript - navigator.geolocation.getCurrentPosition() : fire callback if user says "no"?

这是我的代码的近似值:if(navigator.geolocation){navigator.geolocation.getCurrentPosition(function(position){//success!},function(error){//error},{timeout:10000});}else{//yourbrowser/devicedoesn'tsupportgeolocation}当这段代码运行时,浏览器会正确地请求用户允许跟踪他们的物理位置。如果用户说"is",它会正确运行第一个参数(“成功”)指定的函数。我不清楚的是当用户说“不”时会发生什么。到目前为止,在我

javascript - 使用 Google Geolocation API 通过 MAC 地址对 802.11 接入点进行地理定位

现在大多数浏览器都内置了对GoogleGeolocationAPI的支持。他们通过向Google发送附近802.11接入点(其信标被您的计算机捕获的接入点)的MAC地址来部分地做到这一点。我从不同位置捕获了大量802.11数据包。我正在寻找802.11接入点的地理定位。假设我们只有他们的mac地址。这应该可以通过使用GoogleGeolocationAPI实现。我迄今为止发现的可能对此有帮助的资源包括:GeolocationsourcecodefromMozilla1.9.1codebaseMDNarticleonMonitoringWiFiaccesspointsMDNarticle

javascript - mocha with nodejs assert 挂起/超时为 assert(false) 而不是错误

我有这种Mocha测试:describe'sabah',→beforeEach→@sabahStrategy=_.filter(@strats,{name:'sabah2'})[0].stratit'articlelistshouldbepopulated',(done)→@timeout10000strat=new@sabahStrategy()articles=strat.getArticleStream('barlas')articles.take(2).toArray((result)→_.each(result,(articleList)→//Imaketheassertio

javascript - 生成 DOM 元素时替代 JavaScript `with` 语句

比如说,我有一个JavaScript库来生成如下所示的DOM片段AheadingAparagraph其中库domlib具有适用于任何类型元素的方法,生成上述片段的函数可能如下所示:function(domlib){returndomlib.main(domlib.h1('Aheading'),domlib.p('Aparagraph'));}在此函数中,我更愿意像这样调用domlib方法:main(h1('Aheading'),p('Aparagraph'))为此,我可以将domlib的所有方法放在全局范围内,但我宁愿避免污染全局范围。在我看来,with语句似乎是一个理想的解决方案:f

javascript - 创建小书签 : Append current URL with specific string

我正在尝试创建一个小书签,它将更改我当前所在页面的URL,并加载一个更改了URL字符串的新页面。我已经查看了许多关于小书签的其他主题,但我还没有找到适合我的解决方案。我希望能够更改如下所示的URL:http://mywebsite.com/directory/page.html?referral=Google&visit=1到:http://mywebsite.com/directory/page.html?dog=Fido&cat=Mittens三个目标:1)在?之后删除现有URL中的任何内容标记。2)在问号后附加“dog=Charlie&cat=Mittens”。3)立即使用新UR

javascript - TypeError : value. push is not a function with Angularjs $resource 查询

我从服务器返回一个对象数组:[{id:1,name:"name"},{id:2,name:"name2"}]现在我使用angular-resource$query来获取数据,因为它需要一个数组。收到数据后出现此错误:TypeError:value.pushisnotafunction我从server=给出的响应有问题吗?错误来源://jshint+W018if(action.isArray){value.length=0;forEach(data,function(item){if(typeofitem==="object"){value.push(newResource(item))

javascript - knockout 绑定(bind) 'with' 别名 'as'

我一直在使用knockout并且熟悉'foreach'绑定(bind),我可以在其中使用别名'as'::“with”绑定(bind)有类似的东西吗?我已经用下面的代码试过了,但得到了一个错误:UncaughtReferenceError:Unabletoprocessbinding"with:function(){return{data:$root.profileUser,as:'profile'}}"PreferredName 最佳答案 正如您所演示的,as选项与foreach创建了一个持久的别名,您可以在子上下文中引用该别名。如

javascript - Lodash 不是 TreeShaking with Webpack 和 Webpack 4?

我想从webpack生成的包中摇树lodash以及我未使用的multiply函数我有2个主要文件app.js和math.js它包含以下代码-应用程序.jsimportmapfrom"lodash/map";import{sum}from"./math";console.log("?");console.log(`2+3=${sum(2,3)}`);map([1,2,3],x=>{console.log(x);});数学.jsexportconstsum=(a,b)=>a+b;exportconstmultiply=(m,n)=>m*n;webpack.config.jsconstpat