2017-03-27 4 views
0

このジオフェンシングは初めてです。誰も、次の属性で設定するために、geofence一意のIDを取得する方法を教えてもらえますか?イオンでジオフェンスの固有の識別子を取得する方法は?

window.geofence.addOrUpdate({ 
    id:    String, //A unique identifier of geofence 
    latitude:  Number, //Geo latitude of geofence 
    longitude:  Number, //Geo longitude of geofence 
    radius:   Number, //Radius of geofence in meters 
    transitionType: Number, //Type of transition 1 - Enter, 2 - Exit, 3 - Both 
    } 

誰でも助けてください!

答えて

0

小さなコードスニペットを使用して、ユニークなIDを生成するために、長さが8以下の一意のIDを生成することができます。

(function() { 
    function IDGenerator() { 

     this.length = 8; 
     this.timestamp = +new Date; 

     var _getRandomInt = function(min, max) { 
      return Math.floor(Math.random() * (max - min + 1)) + min; 
     } 

     this.generate = function() { 
      var ts = this.timestamp.toString(); 
      var parts = ts.split("").reverse(); 
      var id = ""; 

      for(var i = 0; i < this.length; ++i) { 
       var index = _getRandomInt(0, parts.length - 1); 
       id += parts[index]; 
      } 

      return id; 
     } 


    } 


    document.addEventListener("DOMContentLoaded", function() { 
     var btn = document.querySelector("#generate"), 
      output = document.querySelector("#output"); 

     btn.addEventListener("click", function() { 
      var generator = new IDGenerator(); 
      output.innerHTML = generator.generate(); 

     }, false); 

    }); 


})(); 

マークアップは

<p><button id="generate">Generate</button></p> 
<p><code id="output"></code></p>  

はそれをuを役に立てば幸いです。

+0

ありがとうございました。つまり、私たちはgenfencingのために別々のidを別々に生成することができますか? –

+0

はい私たちは別々に@Priyaを生成することができます –

+0

大丈夫です。私たちに教えてください、私たちはGoogle APIを有効にしてジオフェンシングを実現する必要がありますか? –

関連する問題