Example #1
0
Regions.fromJson = function(jsonMap) {

	var typeName = jsonMap.typeName;
	if (!_.isString(typeName) || _.isEmpty(typeName)) {
		throw new TypeError('jsonMap need to have a key "typeName"');
	}

	var identifier = jsonMap.identifier;

	var region = null;
	if (typeName === 'CircularRegion') {

		var latitude = jsonMap.latitude;
		var longitude = jsonMap.longitude;
		var radius = jsonMap.radius;
		region = new CircularRegion(identifier, latitude, longitude, radius);

	} else if (typeName === 'BeaconRegion') {

		var uuid = jsonMap.uuid;
		var major = jsonMap.major;
		var minor = jsonMap.minor;
		region = new BeaconRegion(identifier, uuid, major, minor);
	} else {
		console.error('Unrecognized Region typeName: ' + typeName);
	}

	return region;
};
Example #2
0
Region.checkIdentifier = function (identifier) {
	if (!_.isString(identifier)) {
		throw new TypeError(identifier + ' is not a String.');
	}
	if (_.isEmpty(identifier)) {
		throw new Error("'identifier' cannot be an empty string.");
	}
};
Example #3
0
Delegate.safeTraceLogging = function(message) {
	if (!_.isString(message)) {
		return;
	}
	try {
		cordova.plugins.locationManager.appendToDeviceLog(message);
	} catch (e) {
		console.error('Fail in safeTraceLogging()' + e.message, e);
	}
};
Example #4
0
LocationManager.prototype._onDelegateCallback = function (deferred, pluginResult) {

	this.appendToDeviceLog('_onDelegateCallback() ' + JSON.stringify(pluginResult));

	if (pluginResult && _.isString(pluginResult['eventType'])) { // The native layer calling the DOM with a delegate event.
		this._mapDelegateCallback(pluginResult);
	} else if (Q.isPending(deferred.promise)) { // The callback ID registration finished, runs only once.
		deferred.resolve();
	} else { // The native layer calls back the delegate without specifying an event, coding error.
		console.error('Delegate registration promise is already been resolved, all subsequent callbacks should provide an "eventType" field.');
	}
};