2017-03-27 38 views
0

我是這個地理圍欄的新手。任何人都可以告訴我如何獲得地理柵欄唯一的ID,以設置以下屬性?如何獲得geofence在離子中的唯一標識符?

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>  

希望它可以幫助ü。

+0

謝謝。你的意思是,我們可以獨立生成唯一的ID分配給genfencing? –

+0

是的,我們可以單獨生成@Priya –

+0

好的。你能告訴我,我們需要啓用任何谷歌API來實現geofencing? –