Advertisement
rujing

Untitled

Sep 2nd, 2020
1,145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Определение города
  2.   var userCity = getCookie('USER_CITY');
  3.  
  4.   if(!userCity)
  5.   {
  6.  
  7.     ymaps.ready(function () {
  8.       var location = ymaps.geolocation;
  9.  
  10.       // Получение местоположения
  11.       location.get({
  12.           provider: 'yandex',
  13.               mapStateAutoApply: true,
  14.               kind: 'locality',
  15.           })
  16.       .then(
  17.           function(result) {
  18.  
  19.             // Получение местоположения пользователя.
  20.             var userAddress = result.geoObjects.get(0).properties.get('name');
  21.             var userArea = result.geoObjects.get(0).properties.get('description');
  22.  
  23.             // Отображаем попап
  24.             $('[data-pp="choosecity"] .title > strong').text(userAddress);
  25.             $('[data-call="choosecity"] > span').text(userAddress);
  26.             $('#overlay, [data-pp="choosecity"]').fadeIn();
  27.  
  28.             // Клик подтверждения
  29.             $('[data-pp="choosecity"] [data-close="data-close"]').click(function(){
  30.  
  31.             // Записываем куки
  32.             setCookie('USER_CITY', userAddress, {'expires' : 604800, 'path' : '/'});
  33.  
  34.             $('[data-call="choosecity"] > span').text(userAddress);
  35.  
  36.           });
  37.  
  38.           },
  39.           function(err) {
  40.               console.log('Ошибка: ' + err)
  41.           }
  42.       );
  43.     });
  44.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement