Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I do agree that setting the value of an input via jQuery in an ember app is not the way to go. Ember does really well with binding to properties. I would suggest that since you redirect to Locate route on initial load, move the getLoaction logic to the LocateController or set it inside the route setupController hook see here <a href="http://emberjs.com/guides/controllers/representing-a-single-model-with-objectcontroller/" rel="nofollow">(see here for setupController example)</a>... You can also set the properties this on your App instance, if you wanted to have access to them.</p> <p>So, instead of this:</p> <pre><code>var GeoLocation; GeoLocation = (function(location){ $('#latitude').val(location.coords.latitude), $('#longitude').val(location.coords.longitude) }); navigator.geolocation.getCurrentPosition(GeoLocation) </code></pre> <p>I would do it in the route:</p> <pre><code>App.LocateRoute = Ember.Route.extend({ setupController: function(controller, model) { navigator.geolocation.getCurrentPosition(controller.geoLocation) } }); App.LocateController = Ember.Controller.extend({ geoLocation: function(location){ this.set('latitude', location.coords.latitude); this.set('longitude', location.coords.longitude); } }); </code></pre> <p>Now your Locate controller has the 2 properties 'latitude' and 'longitude' defined. You can bind to them in your template. (BTW, your template already look correct for the binding.)</p> <p>You can also set the properties this on your App instance, if you wanted to have access to them globally, then change the bindings to point to 'App.longitude' and 'App.latitude'.</p> <pre><code>App.LocateController = Ember.Controller.extend({ geoLocation: function(location){ Ember.set(App, 'latitude', location.coords.latitude); Ember.set(App, 'longitude', location.coords.longitude); } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload