forked from onury/geolocator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geolocator.min.js
7 lines (7 loc) · 3.11 KB
/
geolocator.min.js
1
2
3
4
5
6
7
/*
Geolocator Javascript Lib v.1.2.9
(c) 2014-2015 Onur Yildirim ([email protected])
https://github.com/onury/geolocator
MIT License
*/
(function(){function j(a){return a&&a.Object===Object?a:null}function k(){"use strict";function g(a,c,d){function f(a,b){d&&e.parentNode&&e.parentNode.removeChild(e),"function"==typeof a&&a(b)}var e=document.createElement("script");e.async=!0,e.readyState?e.onreadystatechange=function(a){("loaded"===e.readyState||"complete"===e.readyState)&&(e.onreadystatechange=null,f(c))}:e.onload=function(a){f(c)},e.onerror=function(c){var d="Could not load source at "+String(a).replace(/\?.*$/,"");f(b,new Error(d))},e.src=a,document.getElementsByTagName("head")[0].appendChild(e)}function h(a){function b(){l.__glcb&&delete l.__glcb,google.load("maps",d,{other_params:"",callback:a})}void 0!==window.google&&void 0!==google.maps?a&&a():void 0!==window.google&&void 0!==google.loader?b():(l.__glcb=b,g(c+"?callback=geolocator.__glcb"))}function i(a,b){function d(a,c){c===google.maps.GeocoderStatus.OK&&b&&b(a)}var c=new google.maps.Geocoder;c.geocode({latLng:a},d)}function j(a){if(a&&a.length>0){var b,c,d={},e=a[0].address_components;for(b=0;b<e.length;b+=1)c=e[b],c.types&&c.types.length>0&&(d[c.types[0]]=c.long_name,d[c.types[0]+"_s"]=c.short_name);l.location.formattedAddress=a[0].formatted_address,l.location.address={street:d.route||"",neighborhood:d.neighborhood||"",town:d.sublocality||"",city:d.locality||"",region:d.administrative_area_level_1_s||"",country:d.country||"",countryCode:d.country_s||"",postalCode:d.postal_code||"",streetNumber:d.street_number||""}}}function k(b){function d(b){j(b),a&&a.call(null,l.location)}var c=new google.maps.LatLng(b.latitude,b.longitude);i(c,d)}function m(c,d){function e(c){l.locateByIP(a,b)}function f(a){l.location={ipGeoSource:null,coords:a.coords,timestamp:(new Date).getTime()},k(l.location.coords)}function g(a){e(a)}l.location=null,navigator.geolocation?navigator.geolocation.getCurrentPosition(f,g,d):e(new Error("geolocation is not supported."))}function n(c){function e(){void 0!==window.Geo&&(l.location=JSON.parse(JSON.stringify(window.Geo)),delete window.Geo,d=!0),1==d?a&&a.call(null,l.location):b&&b(new Error(c||"Could not get location."))}var d=!1;l.location=null,delete l.__ipscb,e()}var a,b,c="https://www.google.com/jsapi",d="3.23",e="//geoiplookup.wikimedia.org/";return{location:null,locate:function(c,d,e,f){function g(){m(e,f)}a=c,b=d,h(g)},locateByIP:function(c,d){a=c,b=d,l.__ipscb=n,g(e,n,!0)},isPositionError:function(a){return"[object PositionError]"===Object.prototype.toString.call(a)}}}var a={"function":!0,object:!0},b=a[typeof exports]&&exports&&!exports.nodeType?exports:void 0,c=a[typeof module]&&module&&!module.nodeType?module:void 0,d=c&&c.exports===b?b:void 0,e=j(b&&c&&"object"==typeof global&&global),f=j(a[typeof self]&&self),g=j(a[typeof window]&&window),h=j(a[typeof this]&&this),i=e||g!==(h&&h.window)&&g||f||h||Function("return this")(),l=k();(g||f||{}).geolocator=l,"function"==typeof define&&"object"==typeof define.amd&&define.amd?define(function(){return l}):b&&c?(d&&((c.exports=l).geolocator=l),b.geolocator=l):i.geolocator=l}).call(this);