Click to search on your search term.
Subscribe to Fig Leaf Tutorials

Need help with a project? Contact us at
From code reviews to project "jumpstarts" and full life-cycle development, we've got you covered!
Check out our case studies!
Follow us on Twitter!
Click here to join our Facebook group!

Ready to upgrade your skills? Try these instructor-led classes in Washington, DC:

Getting the Current Location

Page of 168

Using the Ext.util.Geolocation class enables you to retrieve the device's current geographc position at scheduled intervals.

As illustrated by the following code sample, determining a device's position is an asynchronous event due to the latency associated with locating the proper satellites from which to calculate a "fix". When the position of the device has been calculated, the class fires a locationupdate event that is passed the current location as an argument. You can programatically request that the current location be recalculated by invoking the Ext.util.Geolocation.updateLocation() method.

By default this class invokes the browser's native navigator.geolocation class.

var geo = Ext.create('Ext.util.Geolocation', {
 autoUpdate: false,
 listeners: {
  locationupdate: function(geo) {
     var currentLat = geo.getLatitude();
     var currentLng =  geo.getLongitude();
     var altitude = geo.getAltitude();
     var speed = geo.getSpeed();
     var heading= geo.getHeading();
  locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
       Ext.Msg.alert('Timeout occurred',"Could not get current position");
       alert('Error occurred.');

Additional configuration options include the following:

Config PropertyDescription
AllowHighAccuracyBoolean. Defaults to false. When set to true, the user will typically be prompted to approve the request. Using this option may result in higher latency and greater power consumption as it activates the device's internal GPS sensor instead of calulating position using wi-fi networks
frequencyNumber. Defaults to 10000. The interval to use for re-calculating the current position.
autoUpdateBoolean. Defaults to true. When true, the device's position is calculated at regular intervals, determined by the value of the frequency config property.
timeoutNumber. Defaults to Infinity. The maximum number of ms allowed to elapse between a location update operation and the corresponding locationupdate event being raised. If the current position was not successfully acquired before the timeout elapses a locationerror event is raised.
Page of 168
comments powered by Disqus