Sha256: 858bf36ea91ad7f2660140177c6ee8a31f20ee26a61e390334a7b3cb15e6eeeb
Contents?: true
Size: 1.1 KB
Versions: 8
Compression:
Stored size: 1.1 KB
Contents
$(document).on('ready formily_loaded', function() { var locationInputs = $('input[data-location], p.static-text[data-location], textarea[data-location]'); if(locationInputs.length > 0) { if(navigator.geolocation){ var geolocationSuccess = function(position){ var latitude = position.coords.latitude; var longitude = position.coords.longitude; var url = window.location.protocol + '//maps.googleapis.com/maps/api/geocode/json?language=en&latlng='; url += latitude + ','; url += longitude; $.get(url, function(data) { locationInputs.each(function(_, el){ var self = $(el); if(self.data('location') == 'address') { self.val(data.results[0].formatted_address); } else { self.val(latitude + ', ' + longitude); } }); }); }; var geolocationError = function(){ self.val(''); console.error('Unable to retrieve your location'); }; navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError); } } });
Version data entries
8 entries across 8 versions & 1 rubygems