我想获得用户Geolocation。一旦我得到坐标,我想根据Geolocation加载记录。如果结果超过1,请显示索引页
LHW.Store = DS.Store.extend
revision: 11
adapter: DS.RESTAdapter
DS.RESTAdapter.reopen
namespace: 'api'
LHW.Company = DS.Model.extend
name: DS.attr 'string'
address: DS.attr 'string'
city: DS.attr 'string'
LHW.IndexRoute = Ember.Route.extend
setupController: (controller, route) ->
# get Geolocation
_route = @
navigator.geolocation.getCurrentPosition ((location) ->
#success
_route.geoLocation(location)
), (error) ->
#error
switch(error.code)
when error.PERMISSION_DENIED then console.log "User denied the request for Geolocation."
when error.POSITION_UNAVAILABLE then console.log "Location information is unavailable."
when error.TIMEOUT then console.log "The request to get user location timed out."
when error.UNKNOWN_ERROR then console.log "An unknown error occurred."
geoLocation: (location) ->
_route = @
@get('store').findQuery('company',{longitude: location.coords.longitude, latitude: location.coords.latitude}).then ((data) =>
_route.controllerFor('companies').set('content', data)
if data.get('length') > 1
_route.transitionTo('companies');
), (error) ->
console.log "error"
LHW.CompaniesRoute = Ember.Route.extend()
LHW.IndexController = Ember.ArrayController.extend
beforeModel: ->
console.log 'before'
所以这就是我现在所拥有的。但这有一些问题
所以这主要是一个流程问题,我无法解决这个问题,异步地理定位不会让事情变得更容易......