Can position data be modified in onUpdate while gps is on?

I have a var in onUpdate:

var g = Position.getInfo().position;

underneath it also in onUpdate it says:

if g != null {

g = g.toDegrees();

find (g[0],g[1]);  (which is of course the lat and longitude of g)

g = null; 

……(excluded bitmap stuff here that occurs when g is not null………  }

I would like to on each tap of the upper, lower, left or right of the screen modify g[0] and g[1] (aka the latitude and longitude) by 1.0 degrees and that to not reset until I tapped the center of the screen. Now I’ve already got the delegate checking for the location of onTap but I am not sure how to modify g[0] and g[1]. Finally due to it being in onUpdate I am unsure if when onUpdate updates itself whether this would even work.

Would anybody happen to know how to do this?

Help is much appreciated.

  • The value g is a position object that your application owns. It is not shared by the system in any way. You are free to modify it to your hearts content.

    As this code is, you are getting the current position, overwriting it, and then throwing that away. What you want to do is capture the current position in a variable, and modify that variable from your InputDelegate and display the result in the View. Something like this.

    import Position;
    import WatchUi;
    
    class MapModel
    {
        hidden var mLatitude as Float;
        hidden var mLongitude as Float;
        
        function initialize(position as Position.Location) {
            var degrees = position.toDegrees();
            setPosition(degrees[0], degrees[1]);
        }
        
        function getLatitude() as Float {
            return mLatitude;
        }
    
        function getLongitude() as Float {
            return mLongitude;
        }
    
        function setPosition(lat as Float, lon as Float) as Void {
            mLatitude = lat;
            mLongitude = lon;
        }
    }
    
    class MapDelegate extends WatchUi.BehaviorDelegate {
    
        hidden var mMapModel as MapModel;
        hidden var mHeight as Number;
        hidden var mWidth as Number;
        
        function initialize(mapModel as MapModel, screenWidth as Number, screenHeight as Number) {
            BehaviorDelegate.initialize();
            mMapModel = mapModel;
            mHeight = screenHeight;
            mWidth = screenWidth;
        }
        
        function onTap(evt as ClickEvent) {
            var xOffset = mScreenWidth / 10;
            var yOffset = mScreenHeight / 10;
            
            var leftEdge = xOffset;
            var rightEdge = mScreenWidth - xOffset;
            
            var topEdge = yOffset;
            var bottomEdge = mScreenHeight - yOffset;
            
            var posX = mModel.getLongitude();
            var posY = mModel.getLatitude();
    
            var coords = evt.getCoordinates();
            if (coords.x < leftEdge) {
                posX -= 1.0;
            } else if (coords.x > rightEdge) {
                posX += 1.0;
            }
            
            if (coords.y < topEdge) {
                posY -= 1.0;
            } else if (coords.y > bottomEdge) {
                posY += 1.0;
            }
            
            mModel.setPosition(posY, posX);
            WatchUi.requestUpdate();
            
            return true;
        }
    }
    
    class MapView extends WatchUi.MapView {
    
        hidden var mModel as MapModel;
        
        function initialize(mapModel as MapModel) {
            MapView.initialize();
            mMapModel = mapModel;
        }
        
        function onUpdate(dc) {
            var lat = mMapModel.getLatitude();
            var lon = mMapModel.getLongitude();
            
            // draw at lat,lon
        }
    }
    

  • Would this work on 3.0 devices such as the vivoactive 3?