将LatLong存储在Cookie中

时间:2018-07-16 15:04:08

标签: javascript jquery cookies jquery-cookie

我想做的是,将用户LatLong存储在Cookie中,但在用户允许位置后未设置Cookie,没有错误等。

var successCallback = function(position) {
  $.cookie('latlong', position.coords.latitude + ',' + position.coords.longitude, {
    expires: 360,
    path: '/'
  });
};

var errorCallback = function(error) {
  var errorMessage = 'Unknown error';
  switch (error.code) {
    case 1:
      errorMessage = 'Permission denied';
      break;
    case 2:
      errorMessage = 'Position unavailable';
      break;
    case 3:
      errorMessage = 'Timeout';
      break;
  }
};

var options = {
  enableHighAccuracy: true,
  timeout: 10000,
  maximumAge: 0
};

navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="/plugin/cookie/jquery.cookie.js"></script>

0 个答案:

没有答案