Guest User

Untitled

a guest
May 7th, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. var win = Titanium.UI.currentWindow;
  2.  
  3.  
  4. var isAndroid = false;
  5.  
  6. if (Titanium.Platform.name == 'android') {
  7. isAndroid = true;
  8. menu = Titanium.UI.Android.OptionMenu.createMenu();
  9. }
  10.  
  11. Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
  12.  
  13. //
  14. // SET DISTANCE FILTER. THIS DICTATES HOW OFTEN AN EVENT FIRES BASED ON THE DISTANCE THE DEVICE MOVES
  15. // THIS VALUE IS IN METERS
  16. //
  17. Titanium.Geolocation.distanceFilter = 5;
  18.  
  19. //
  20. // GET CURRENT POSITION - THIS FIRES ONCE
  21. //
  22. Titanium.Geolocation.getCurrentPosition(function(e)
  23. {
  24. if (e.error)
  25. {
  26. alert('Cannot get your current location, is your GPS on?');
  27. return;
  28. }
  29.  
  30. var longitude = e.coords.longitude;
  31. var latitude = e.coords.latitude;
  32. var altitude = e.coords.altitude;
  33. var heading = e.coords.heading;
  34. var accuracy = e.coords.accuracy;
  35. var speed = e.coords.speed;
  36. var timestamp = e.coords.timestamp;
  37. var altitudeAccuracy = e.coords.altitudeAccuracy;
  38.  
  39.  
  40. //
  41. //CREATE MAP VIEW
  42. //
  43. var mapview = Titanium.Map.createView({
  44. mapType: Titanium.Map.STANDARD_TYPE,
  45. region: {latitude: latitude, longitude: longitude, latitudeDelta:0.01, longitudeDelta:0.01},
  46. animate:true,
  47. regionFit:true,
  48. userLocation:true,
  49. });
  50.  
  51. Titanium.UI.currentWindow.add(mapview);
  52.  
  53.  
  54. //
  55. // NAVBAR BUTTONS
  56. //
  57. var removeAll = null;
  58.  
  59. if (!isAndroid) {
  60. removeAll = Titanium.UI.createButton({
  61. style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED,
  62. title:'Remove All'
  63. });
  64. } else {
  65. removeAll = Titanium.UI.Android.OptionMenu.createMenuItem({title:'Remove All'});
  66. }
  67. removeAll.addEventListener('click', function()
  68. {
  69. mapview.removeAllAnnotations();
  70. });
  71. if (!isAndroid) {
  72. win.rightNavButton = removeAll;
  73. }
  74. //
  75. // TOOLBAR BUTTONS
  76. //
  77.  
  78.  
  79. // button to change map type to SAT
  80. var sat = null;
  81. if (!isAndroid) {
  82. sat = Titanium.UI.createButton({
  83. title:'Sat',
  84. style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
  85. });
  86. } else {
  87. sat = Titanium.UI.Android.OptionMenu.createMenuItem({title : 'Sat'});
  88. }
  89. sat.addEventListener('click',function()
  90. {
  91. // set map type to satellite
  92. mapview.setMapType(Titanium.Map.SATELLITE_TYPE);
  93. });
  94.  
  95. // button to change map type to STD
  96. var std = null;
  97. if (!isAndroid) {
  98. std = Titanium.UI.createButton({
  99. title:'Std',
  100. style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
  101. });
  102. } else {
  103. std = Titanium.UI.Android.OptionMenu.createMenuItem({title : 'Std'});
  104. }
  105. std.addEventListener('click',function()
  106. {
  107. // set map type to standard
  108. mapview.setMapType(Titanium.Map.STANDARD_TYPE);
  109. });
  110.  
  111. // button to change map type to HYBRID
  112. var hyb = null;
  113. if (!isAndroid) {
  114. hyb = Titanium.UI.createButton({
  115. title:'Hyb',
  116. style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
  117. });
  118. } else {
  119. hyb = Titanium.UI.Android.OptionMenu.createMenuItem({title : 'Hyb'});
  120. }
  121. hyb.addEventListener('click',function()
  122. {
  123. // set map type to hybrid
  124. mapview.setMapType(Titanium.Map.HYBRID_TYPE);
  125. });
  126. if (!isAndroid) {
  127. win.setToolbar([flexSpace,std,flexSpace,hyb,flexSpace,sat]);
  128. } else {
  129. menu.add(std);
  130. menu.add(hyb);
  131. menu.add(sat);
  132. Titanium.UI.Android.OptionMenu.setMenu(menu);
  133. }
  134.  
  135. });
Advertisement
Add Comment
Please, Sign In to add comment