@abcum/ember-location 中文文档教程

发布于 5年前 浏览 26 项目主页 更新于 3年前

ember-location

在 Ember.js 应用程序中使用地理定位的实用程序。

Usage

Installation

ember install @abcum/ember-location

Methods

find()

find 方法 ret 使用 HTML5 Geolocation API 从浏览器获取位置。 它返回一个 Ember.RSVP.Promise,如果 HTML5 Geolocation API 不可用,或者当前坐标无法找到,它将拒绝,如果定位成功,将解析。 此外,当前的地理位置被保存到 current 属性中。

this.get('location').find({ timeout:5000 }).then(function(result) {
    // Access the user's location using `result` or `this.location.current`
});

它接受一个可选对象作为第一个参数,可用于自定义查询。 如果省略,它将默认为此处列出的值。

{
    enableHighAccuracy: false,
    timeout: Infinity,
    maximumAge: 0
}

watch()

watch 方法使用 HTML5 Geolocation API 从浏览器持续检索和跟踪位置。 它返回一个 Ember.RSVP.Promise,如果 HTML5 Geolocation API 不可用,或者当前坐标无法找到,它将拒绝,如果定位成功,将解析。 此外,当前的地理位置会持续保存到 current 属性中。

this.get('location').watch({ timeout:5000 }).then(function(result) {
    // Access the user's location using `result` or `this.location.current`
});

它接受一个可选对象作为第一个参数,可用于自定义查询。 如果省略,它将默认为此处列出的值。

{
    enableHighAccuracy: false,
    timeout: Infinity,
    maximumAge: 0
}

Properties

current 属性存储使用 HTML5 Geolocation API 检索的最新定位数据,此处显示了一个示例。

{
  coords: {
    accuracy: 75,
    altitude: null,
    altitudeAccuracy: null,
    heading: null,
    latitude: 51.165,
    longitude: 0.248,
    speed: null
  },
  timestamp: 1470156731858
}

Examples

在显示路线之前等待当前位置。

export default Ember.Route.extend({
    model() {
        return this.get('location').watch();
    }
})

使用 current 对象在模板中的地图上显示当前位置。

{{example-map lat=location.current.coords.latitude lng=location.current.coords.longitude}}

Development

  • make install (install bower and ember-cli dependencies)
  • make upgrade (upgrade ember-cli to the specified version)
  • make tests (run all tests defined in the package)

ember-location

A utility for working with geolocation in an Ember.js app.

Usage

Installation

ember install @abcum/ember-location

Methods

find()

The find method retrives the location from the browser using the HTML5 Geolocation API. It returns a Ember.RSVP.Promise, which will reject if the HTML5 Geolocation API is not available, or if the current coordinates are not able to be found, and will resolve if the positioning was successful. In addition the current geolocation position is saved to the current property.

this.get('location').find({ timeout:5000 }).then(function(result) {
    // Access the user's location using `result` or `this.location.current`
});

It accepts an optional object as the first argument which can be used to customise the query. If omitted it will default to the values listed here.

{
    enableHighAccuracy: false,
    timeout: Infinity,
    maximumAge: 0
}

watch()

The watch method continually retrieves and tracks the location from the browser using the HTML5 Geolocation API. It returns a Ember.RSVP.Promise, which will reject if the HTML5 Geolocation API is not available, or if the current coordinates are not able to be found, and will resolve if the positioning was successful. In addition the current geolocation position is continually saved to the current property.

this.get('location').watch({ timeout:5000 }).then(function(result) {
    // Access the user's location using `result` or `this.location.current`
});

It accepts an optional object as the first argument which can be used to customise the query. If omitted it will default to the values listed here.

{
    enableHighAccuracy: false,
    timeout: Infinity,
    maximumAge: 0
}

Properties

The current property stores the latest positioning data which was retrieved using the HTML5 Geolocation API, an example of which is displayed here.

{
  coords: {
    accuracy: 75,
    altitude: null,
    altitudeAccuracy: null,
    heading: null,
    latitude: 51.165,
    longitude: 0.248,
    speed: null
  },
  timestamp: 1470156731858
}

Examples

Wait for the current position before displaying the route.

export default Ember.Route.extend({
    model() {
        return this.get('location').watch();
    }
})

Display the current position on a map in the template using the current object.

{{example-map lat=location.current.coords.latitude lng=location.current.coords.longitude}}

Development

  • make install (install bower and ember-cli dependencies)
  • make upgrade (upgrade ember-cli to the specified version)
  • make tests (run all tests defined in the package)
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文