1

如何在流星框架内处理地理定位成功和失败事件?更具体地说,调用“navigator.geolocation.getCurrentPosition(showPosition);” 表示如果成功获取位置,则调用 showPosition。每当我定义一个通用 javascript 函数 (function showPosition(position) {}) 时,我都会收到一个 Web 套接字错误。那么如何在meteor框架中调用这些函数呢?

4

2 回答 2

1

检查模块mdg:geolocation

meteor add mdg:geolocation

在您的代码中使用它之后:

Geolocation.currentLocation()
于 2015-07-07T05:34:02.073 回答
0

这不是特定的流星功能。它适用于地理定位兼容的浏览器。获得位置后,您可以通过 Meteor 发送或保存它。

客户端js:(确保集合存在于服务器上)

if (navigator.geolocation)
{
    navigator.geolocation.getCurrentPosition(showPosition);
}
   else{
       console.log("Geolocation is not supported by this browser.";
   }
}

function showPosition(position)
{
    Locations.insert({latitude: position.coords.latitude, 
                      longitude: position.coords.longitude});
}
于 2013-07-07T00:55:32.377 回答