आप geolocator.js का उपयोग कर सकते हैं आसानी से टाइमजोन और अधिक प्राप्त करने के लिए ...
यह Google API का उपयोग करता है जिसके लिए एक कुंजी की आवश्यकता होती है। तो, पहले आप जियोलोकेटर को कॉन्फ़िगर करें:
geolocator.config({
language: "en",
google: {
version: "3",
key: "YOUR-GOOGLE-API-KEY"
}
});
यदि आपके पास निर्देशांक हैं तो TimeZone प्राप्त करें:
geolocator.getTimeZone(options, function (err, timezone) {
console.log(err || timezone);
});
उदाहरण आउटपुट:
{
id: "Europe/Paris",
name: "Central European Standard Time",
abbr: "CEST",
dstOffset: 0,
rawOffset: 3600,
timestamp: 1455733120
}
तब पता लगाएँ कि TimeZone और अधिक मिलता है
यदि आपके पास निर्देशांक नहीं हैं, तो आप पहले उपयोगकर्ता की स्थिति का पता लगा सकते हैं।
नीचे दिए गए उदाहरण पहले निर्देशांक प्राप्त करने के लिए HTML5 जियोलोकेशन एपीआई की कोशिश करेंगे। यदि यह विफल या अस्वीकृत हो जाता है, तो यह जियो-आईपी लुक-अप के माध्यम से निर्देशांक प्राप्त करेगा। अंत में, यह समय क्षेत्र और अधिक प्राप्त करेगा ...
var options = {
enableHighAccuracy: true,
timeout: 6000,
maximumAge: 0,
desiredAccuracy: 30,
fallbackToIP: true, // if HTML5 fails or rejected
addressLookup: true, // this will get full address information
timezone: true,
map: "my-map" // this will even create a map for you
};
geolocator.locate(options, function (err, location) {
console.log(err || location);
});
उदाहरण आउटपुट:
{
coords: {
latitude: 37.4224764,
longitude: -122.0842499,
accuracy: 30,
altitude: null,
altitudeAccuracy: null,
heading: null,
speed: null
},
address: {
commonName: "",
street: "Amphitheatre Pkwy",
route: "Amphitheatre Pkwy",
streetNumber: "1600",
neighborhood: "",
town: "",
city: "Mountain View",
region: "Santa Clara County",
state: "California",
stateCode: "CA",
postalCode: "94043",
country: "United States",
countryCode: "US"
},
formattedAddress: "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
type: "ROOFTOP",
placeId: "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
timezone: {
id: "America/Los_Angeles",
name: "Pacific Standard Time",
abbr: "PST",
dstOffset: 0,
rawOffset: -28800
},
flag: "//cdnjs.cloudflare.com/ajax/libs/flag-icon-css/2.3.1/flags/4x3/us.svg",
map: {
element: HTMLElement,
instance: Object, // google.maps.Map
marker: Object, // google.maps.Marker
infoWindow: Object, // google.maps.InfoWindow
options: Object // map options
},
timestamp: 1456795956380
}