Is there a way to retrieve user's favorite locations


  • Paraglider

    I'd like to add quick jump to favorites to my sounding plugin.

    Is there a way to retrieve them ? ie from the store ?

    Thanks



  • if (localStorage && localStorage.getItem('favs')) {
      var favs = JSON.parse(localStorage.getItem('favs'));
      console.log(Object.values(favs));
    }
    

  • Administrator

    @siim There is module fav. Try to use this module and access favs this way. It has methods te retrieve all favs as Array.


  • Paraglider

    Thanks @ivo

    So the "better" way to retrieve favorites is

    import favs from "@windy/favs"; 
    // or
    // var favs = W.require('favs');
    

    Then

    favs.getAll();
    

    returns:

    { 
      "34.492/-119.702": {key: "34.492/-119.702", lat: 34.491843, lon: -119.702396, name: "Santa Barbara", type: "fav", …},
      "36.768/-119.098": {key: "36.768/-119.098", lat: 36.768385, lon: -119.097719, name: "Dunlap", type: "fav", …},
      …
    }
    

    and

    favs.getArray();
    

    returns:

    [
      {key: "37.514/-121.882", lat: 37.513810842731, lon: -121.88215255737303, name: "Mission Peak", type: "fav", …},
      {key: "37.365/-122.246", lat: 37.3650410873092, lon: -122.24594593048094, name: "Windy Hill", type: "fav", …},
      {key: "34.492/-119.702", lat: 34.491843534372784, lon: -119.70239639282227, name: "Santa Barbara", type: "fav", …},
      …
    ]
    

Log in to reply
 

Windyty, S.E. - all rights reserved. Powered by excellent NodeBB
NodeBB & contributors, OSM & contributors, HERE maps