daily pastebin goal
69%
SHARE
TWEET

Untitled

a guest Jan 13th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // file_with_location.js
  3. //
  4. Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
  5. Titanium.Geolocation.distanceFilter = .25;
  6. Ti.Geolocation.purpose = "Callbacks Are Your Friend";
  7. /**
  8. * @param {Object} _callback call on completion of location query                      
  9. */
  10. function currentLocation(_callback) {
  11.     // make the API call
  12.     Ti.Geolocation.getCurrentPosition(function(e) {
  13.  
  14.         // do this stuff when you have a position, OR an error
  15.         if (e.error) {
  16.             Ti.API.error('geo - current position' + e.error);
  17.  
  18.             // to keep it simple, just returning null, could be
  19.             // error information
  20.             if (_callback) {
  21.                 _callback(null);
  22.             }
  23.             return;
  24.         }
  25.  
  26.         // got the location information
  27.         Ti.App.info('got a location ',JSON.stringify(e));
  28.  
  29.         // fire and event containing the location information
  30.         Ti.App.fireEvent('location.updated',e.coords);
  31.        
  32.         // call callback with coords
  33.         if (_callback) {
  34.             _callback(e.coords);
  35.         }
  36.  
  37.     });
  38. }
RAW Paste Data
Top