function validateAndFormatCenter (center) {
		// [lng, lat]
		var defer = $q.defer();

		if (angular.isDefined(center)) {
			if (angular.isDefined(center.autodiscover) && center.autodiscover) {
				$window.navigator.geolocation.getCurrentPosition(function (position) {
					var coordinates = position.coords;

					defer.resolve([coordinates.longitude, coordinates.latitude]);
				}, function (error) {
					defer.resolve(false);
					// defer.reject(error);
				}, {
					enableHighAccuracy: true,
  				timeout: 5000,
  				maximumAge: 0
				});
			} else if (angular.isNumber(center.lat) && angular.isNumber(center.lng) && (center.lng > -180 || center.lng < 180) && (center.lat > -90 || center.lat < 90)) {
				defer.resolve([center.lng, center.lat]);
			} else if (angular.isArray(center) && center.length === 2 && angular.isNumber(center[0]) && angular.isNumber(center[1]) && (center[0] > -180 || center[0] < 180) && (center[1] > -90 || center[1] < 90)) {
				defer.resolve(center);
			} else {
				defer.resolve(false);
			}
		} else {
			defer.resolve(false);
		}

		return defer.promise;
	}
function validateAndFormatCenter (center) {
		
		var defer = $q.defer();

		if (angular.isDefined(center)) {
			if (angular.isDefined(center.autodiscover) && center.autodiscover) {
				$window.navigator.geolocation.getCurrentPosition(function (position) {
					var coordinates = position.coords;

					defer.resolve([coordinates.longitude, coordinates.latitude]);
				}, function (error) {
					defer.resolve(false);
					
				}, {
					enableHighAccuracy: true,
  				timeout: 5000,
  				maximumAge: 0
				});
			} else if (angular.isNumber(center.lat) && angular.isNumber(center.lng) && (center.lng > -180 || center.lng < 180) && (center.lat > -90 || center.lat < 90)) {
				defer.resolve([center.lng, center.lat]);
			} else if (angular.isArray(center) && center.length === 2 && angular.isNumber(center[0]) && angular.isNumber(center[1]) && (center[0] > -180 || center[0] < 180) && (center[1] > -90 || center[1] < 90)) {
				defer.resolve(center);
			} else {
				defer.resolve(false);
			}
		} else {
			defer.resolve(false);
		}

		return defer.promise;
	}
function validateAndFormatCenter ( center ) { // [lng, lat] var defer = $q . defer ( ) ; if ( angular . isDefined ( center ) ) { if ( angular . isDefined ( center . autodiscover ) && center . autodiscover ) { $window . navigator . geolocation . getCurrentPosition ( function ( position ) { var coordinates = position . coords ; defer . resolve ( [ coordinates . longitude , coordinates . latitude ] ) ; } , function ( error ) { defer . resolve ( false ) ; // defer.reject(error); } , { enableHighAccuracy : true , timeout : 5000 , maximumAge : 0 } ) ; } else if ( angular . isNumber ( center . lat ) && angular . isNumber ( center . lng ) && ( center . lng > - 180 || center . lng < 180 ) && ( center . lat > - 90 || center . lat < 90 ) ) { defer . resolve ( [ center . lng , center . lat ] ) ; } else if ( angular . isArray ( center ) && center . length === 2 && angular . isNumber ( center [ 0 ] ) && angular . isNumber ( center [ 1 ] ) && ( center [ 0 ] > - 180 || center [ 0 ] < 180 ) && ( center [ 1 ] > - 90 || center [ 1 ] < 90 ) ) { defer . resolve ( center ) ; } else { defer . resolve ( false ) ; } } else { defer . resolve ( false ) ; } return defer . promise ; }
/*
Check if center is valid and format it.

return: <Array|boolean> If center is valid, return [Lng, Lat] array. If center is invalid, return false.
/ * Check if center is valid and format it .