- var win = Titanium.UI.currentWindow;
- var isAndroid = false;
- if (Titanium.Platform.name == 'android') {
- isAndroid = true;
- menu = Titanium.UI.Android.OptionMenu.createMenu();
- }
- Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
- //
- // SET DISTANCE FILTER. THIS DICTATES HOW OFTEN AN EVENT FIRES BASED ON THE DISTANCE THE DEVICE MOVES
- // THIS VALUE IS IN METERS
- //
- Titanium.Geolocation.distanceFilter = 5;
- //
- // GET CURRENT POSITION - THIS FIRES ONCE
- //
- Titanium.Geolocation.getCurrentPosition(function(e)
- {
- if (e.error)
- {
- alert('Cannot get your current location, is your GPS on?');
- return;
- }
- var longitude = e.coords.longitude;
- var latitude = e.coords.latitude;
- var altitude = e.coords.altitude;
- var heading = e.coords.heading;
- var accuracy = e.coords.accuracy;
- var speed = e.coords.speed;
- var timestamp = e.coords.timestamp;
- var altitudeAccuracy = e.coords.altitudeAccuracy;
- //
- //CREATE MAP VIEW
- //
- var mapview = Titanium.Map.createView({
- mapType: Titanium.Map.STANDARD_TYPE,
- region: {latitude: latitude, longitude: longitude, latitudeDelta:0.01, longitudeDelta:0.01},
- animate:true,
- regionFit:true,
- userLocation:true,
- });
- Titanium.UI.currentWindow.add(mapview);
- //
- // NAVBAR BUTTONS
- //
- var removeAll = null;
- if (!isAndroid) {
- removeAll = Titanium.UI.createButton({
- style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED,
- title:'Remove All'
- });
- } else {
- removeAll = Titanium.UI.Android.OptionMenu.createMenuItem({title:'Remove All'});
- }
- removeAll.addEventListener('click', function()
- {
- mapview.removeAllAnnotations();
- });
- if (!isAndroid) {
- win.rightNavButton = removeAll;
- }
- //
- // TOOLBAR BUTTONS
- //
- // button to change map type to SAT
- var sat = null;
- if (!isAndroid) {
- sat = Titanium.UI.createButton({
- title:'Sat',
- style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
- });
- } else {
- sat = Titanium.UI.Android.OptionMenu.createMenuItem({title : 'Sat'});
- }
- sat.addEventListener('click',function()
- {
- // set map type to satellite
- mapview.setMapType(Titanium.Map.SATELLITE_TYPE);
- });
- // button to change map type to STD
- var std = null;
- if (!isAndroid) {
- std = Titanium.UI.createButton({
- title:'Std',
- style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
- });
- } else {
- std = Titanium.UI.Android.OptionMenu.createMenuItem({title : 'Std'});
- }
- std.addEventListener('click',function()
- {
- // set map type to standard
- mapview.setMapType(Titanium.Map.STANDARD_TYPE);
- });
- // button to change map type to HYBRID
- var hyb = null;
- if (!isAndroid) {
- hyb = Titanium.UI.createButton({
- title:'Hyb',
- style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
- });
- } else {
- hyb = Titanium.UI.Android.OptionMenu.createMenuItem({title : 'Hyb'});
- }
- hyb.addEventListener('click',function()
- {
- // set map type to hybrid
- mapview.setMapType(Titanium.Map.HYBRID_TYPE);
- });
- if (!isAndroid) {
- win.setToolbar([flexSpace,std,flexSpace,hyb,flexSpace,sat]);
- } else {
- menu.add(std);
- menu.add(hyb);
- menu.add(sat);
- Titanium.UI.Android.OptionMenu.setMenu(menu);
- }
- });