Extract points from location on screen relative to center of screen which equals current location.

If the center of the screen was equal to your location, is it possible that tapping on the screen (or in the case of button watches perhaps using a set distance in projected location and the direction you are facing to select) on for example the top left part could result in extracting coords (say for a waypoint) and save them somewhere then set that waypoints location to the center of the screen thus allowing you to select multiple waypoints that then connect as a route?

Just wonderingnif that would be possible for non map devices.

Crude example:

 The birds eye map is just to give an idea of distance.

  • Does this work?

    poi= Application.Storage.getValue(“points”)

    myLocation = new Position.Location({ :latitude => poi[points.size()-2], :longitude => poi[points.size()-1], :format => :degrees});

    etc code.

  • You could do that, but you probably don't need the methods that position.location provides. It would be simpler to use a two element array containing the last two elements in points. It depends on whether the open source code needs that object or just the lat and long

  • The open source code that handles the position looks like this:

    function onUpdate(){

    g = Position.getInfo().position;

     if (g!=null) {

    g = g.toDegrees();

    find (g[0], g[1]);

    g = null;

    (fancy bit of maths that does the alignment of the map) 

    }}

  • You have g[0] and g[1], which is just those lat and long coordinates in degrees, so just call find() with those last two points in the array 

  • So from this: 

    function onUpdate(){

    var g = Position.getInfo().position;

     if (g!=null) {

    g = g.toDegrees();

    find (g[0], g[1]);

    g = null;

    (fancy bit of maths that does the alignment of the map) 

    }}

    to this

    function onUpdate(){

    var points = Application.Storage.getValue(“points”)

    var g = points;

     if (g!=null) {

    g = g.toDegrees();

    find (g[g.size()-2], g[g.size()-1]);

    g = null;

    (fancy bit of maths that does the alignment of the map) 

    }}

  • Yes, but you don't need the g.toDegrees(). Delete that line. It will fail because g is the list of points

  • It doesn't seem to like it. No errors, just the map isn't moving along with the position change. Perhaps you can see the problem. Note the code which connects the cut pieces of the map together is not shown, just the one that positions then draws it.

    //This is the view (part of it anyway)
    //for some reason it does update the coords (until the fit file time ends that is) and thus the location, just not the map for some reason.
    
    function onUpdate(dc as Dc) as Void {
        { 
            
            var points = Application.Storage.getValue("points");
            
            var g = points;
              
            if (g != null)
    
            {  
    
                find(g[g.size()-2], g[g.size()-1]);
    
                g = null;
    
     
    
                for(var i=0, yy=y-imgs-my; yy<y+imgs; yy+=imgs) {
    
                    for(var xx=x-imgs-mx; xx<x+imgs; xx+=imgs, i++) {
    
                        if(ar[i]!=null){
    
                            dc.drawBitmap(xx, yy, WatchUi.loadResource(ar[i]));}}}
    
           
                }
            
            
    //Delegate (this works)
    public function onTap(clickEvent) as Boolean {
           var c = clickEvent.getCoordinates();
           var y = c[0];
           var x = c[1]; 
           var clklon = (120 - x);
           var clklat = (120 - y);
           if (posnInfo !=null) {
           var position = posnInfo.position;
           lat = position.toDegrees()[0];
           lon = position.toDegrees()[1];
           lat = (lat - (5 * (clklat/240)));
           lon = (lon - (5 * (clklon/240)));
           System.println(lat);
           System.println(lon);
           var points = [lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,
                         lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon,lat,lon];
                         Application.Storage.setValue("points",points);
           var existingPoints = Application.Storage.getValue("points");
           existingPoints = existingPoints.addAll([lat,lon]);
              Application.Storage.setValue("points", existingPoints);}
           
           
           WatchUi.requestUpdate;
           return true;}

  • Hi, Couple of things. On line 48 onwards, you need to change the code to:

    var existingPoints = Application.Storage.getValue("points"); //get the existing
    
    if(existingPoints==null){
      existingPoints =[]; //create a blank array if there isn't one already
    }
    
    existingPoints = existingPoints.addAll([lat,lon]); //add the new ones
    Application.Storage.setValue("points", existingPoints); //save it down

    Then print out the values you send to find() on line 15 to see what you're sending.  You might want to compare that to your current position to check it makes some sense:

    System.println("lat=" + g[g.size()-2] + ", long=" +  g[g.size()-1]);

    you might want to set g=existingPoints[existingPoints.size()-2, existingPoints.size()-1], and then you can leave the code below as g[0], g[1] and any use of that variable in the code below will be indentical to what it was before.

    ------------

    FYI - As a matter of style, favour returning early in functions if something is null, so you can do

    if(posnInfo==null){

      return false; 

    }

    and then you don't need to indent the rest of the function and it reduces the complexity of reading code.

  • Okay, I have good news, the println code shows it works, it changes my position. The slightly confusing news is it does not change it by much but rather by like 0.0003 which explains why the map wasn’t changing it’s appearance, I think somewhere i’ve got the maths wrong.