Η μέθοδος Geolocation.getCurrentPosition()
χρησιμοποιείται ώστε να ανακτηθεί η τρέχουσα τοποθεσία της συσκευής.
Συντακτικό
navigator.geolocation.getCurrentPosition(success[, error[, options]])
Παράμετροι
- success
- Μία συνάρτηση επανάκλησης (callback function) που δέχεται ένα αντικείμενο τύπου
Position
ως μοναδική παράμετρο εισόδου. - error Optional
- Μία προαιρετική συνάρτηση επανάκλησης (callback function) που δέχεται ένα αντικείμενο τύπου
PositionError
ως μοναδική παράμετρο εισόδου. - options Optional
- Ένα προαιρετικό αντικείμενο τύπου
PositionOptions
.
Παράδειγμα
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log('Latitude : ' + crd.latitude);
console.log('Longitude: ' + crd.longitude);
console.log('More or less ' + crd.accuracy + ' meters.');
};
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
};
navigator.geolocation.getCurrentPosition(success, error, options);
Προδιαγραφές
Προδιαγραφή | Κατάσταση | Σχόλιο |
---|---|---|
Geolocation API | Recommendation | Αρχικές προδιαγραφές |
Συμβατότητα προγράμματος περιήγησης
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Χαρακτηριστικό | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Βασική υποστήριξη | 5 | 3.5 (1.9.1) | 9 | 10.60 Αφαιρέθηκε στην έκδοση 15.0 Επαναπροστέθηκε στην έκδοση 16.0 |
5 |
Χαρακτηριστικό | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Βασική υποστήριξη | ? | ? | 4.0 (4) | ? | 10.60 | ? |