Перевод не завершен. Пожалуйста, помогите перевести эту статью с английского.
Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Метод Geolocation.getCurrentPosition() используется для получения текущего местоположения устройства.
Синтаксис
navigator.geolocation.getCurrentPosition(success[, error[, options]])
Параметры
- success
- Функция обратного вызова, которая принимает объект
Positionв качестве единственного входного параметра. - error Необязательный
- Необязательная функция обратного вызова, принимающая объект
PositionErrorкак единственный входной параметр. - options Необязательный
- Необязательный объект
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 | Рекомендация | Начальная спецификация. |
Поддержка браузерами
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!
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | 5 | (Да) | 3.5 (1.9.1) | 9 | 10.60 Removed in 15.0 Reintroduced in 16.0 |
5 |
| Secure context-only | 47 | ? | 55 (55) | Нет | (Да) | (Да) |
| Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
| Basic support | ? | ? | (Да) | 4.0 (4) | ? | 10.60 | ? |
| Secure context-only | Нет | 47 | ? | 55 (55) | Нет | (Да) | (Да) |