Ejemplo n.º 1
0
// Create some coordinates : SET
const coordinates = [
  {'user': '******', 'longitude': '105.828033', 'latitude': '21.007031'},
  {'user': '******', 'longitude': '105.827534', 'latitude': '21.006696'},
  {'user': '******', 'longitude': '105.827116', 'latitude': '21.007317'},
  {'user': '******', 'longitude': '105.828693', 'latitude': '21.007122'},
  {'user': '******', 'longitude': '105.829069', 'latitude': '21.007978'},
  {'user': '******', 'longitude': '105.828720', 'latitude': '21.006150'},
  {'user': '******', 'longitude': '105.828720', 'latitude': '21.006150'},
  {'user': '******', 'longitude': '105.826234', 'latitude': '21.008048'},
  {'user': '******', 'longitude': '105.826213', 'latitude': '21.006961'},
  {'user': '******', 'longitude': '105.826798', 'latitude': '21.007863'}
]

for (let item of coordinates) {
  client.set('people', item.user, [item.latitude, item.longitude]).then(() => {
    console.log('success')
  }).catch(err => {
    console.error(err)
  })
}

// GET:
client.getPoint('people', 'person1').then(obj => {
  console.log(obj)
}).catch(err => {
  console.error(err)
})

client.getPoint('people', 'person2').then(obj => {
  console.log(obj)
Ejemplo n.º 2
0
const Tile38Client = require('tile38-client');
const client = new Tile38Client();

// set a coordinate
client.set('fleet', 'truck1', [33.5123, -112.2693]);

// set a coordinate, with completion handler and error handler
client.set('fleet', 'truck2', [33.5211, -112.2710]).then(() => {
    console.log("done");
}).catch(err => {
    console.error(err);
});


// retrieve it as geojson object:
client.get('fleet', 'truck1').then(obj => {
    // will print:  { object: { type: 'Point', coordinates: [ -112.2693, 33.5123 ] } }
    console.dir(obj);
});

// retrieve it as a simple point
client.getPoint('fleet', 'truck2').then(obj => {
    // will print:  { point: { lat: 33.5211, lon: -112.271 } }
    console.dir(obj);
});


// same as above but adds error handling:
client.getPoint('fleet', 'truck2').then(obj => {
    // will print:  { point: { lat: 33.5211, lon: -112.271 } }