我是这个地理围栏的新手。任何人都可以告诉我如何获得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 :(得分: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>
希望它有所帮助。