var geocoder = require('node-geocoder');
var util = require('util');
var BaseLocation = require('./BaseLocation');

util.inherits(GeoCodioLocation, BaseLocation);

/**
 * Create GM instance
 * @constructor
 */
function GeoCodioLocation() {
  BaseLocation.apply(this, arguments);

  this.setProvider(geocoder('geocodio', 'http', this.get()));
}

/**
 * Geocode address and get latitude\longitude for it
 * @param {String} address
 * @returns {Promise}
 */
GeoCodioLocation.prototype.geocode = function (address) {
  return this.getProvider().geocode(address);
};

/**
 * Reverse geocode to address
 * @param {Number} latitude
 * @param {Number} longitude
 * @returns {Promise}
 */
GeoCodioLocation.prototype.reverse = function (latitude, longitude) {
  return this.getProvider().reverse({lat: latitude, lon: longitude});
};

module.exports = GeoCodioLocation;

import geocoder from 'node-geocoder';
import BaseLocation from './BaseLocation';

export default class GeoCodioLocation extends BaseLocation {
  constructor(...args) {
    super(...args);

    this.setProvider(geocoder('geocodio', 'http', this.get()));
  }

  /**
   * Geocode address and get latitude\longitude for it
   * @param {String} address
   * @returns {Promise}
   */
  geocode(address) {
    return this.getProvider().geocode(address);
  }

  /**
   * Reverse geocode to address
   * @param {Number} latitude
   * @param {Number} longitude
   * @returns {Promise}
   */
  reverse(latitude, longitude) {
    return this.getProvider().reverse({lat: latitude, lon: longitude});
  }
}

Rewrite GeoCodioLocation with ES6