3.6 KiB
3.6 KiB
id, title, challengeType, forumTopicId, localeTitle
id | title | challengeType | forumTopicId | localeTitle |
---|---|---|---|---|
587d7faf367417b2b2512be8 | Get Geolocation Data to Find A User's GPS Coordinates | 6 | 18188 | Получите данные геолокации, чтобы найти GPS-координаты пользователя |
Description
if (navigator.geolocation) {Во-первых, он проверяет
navigator.geolocation.getCurrentPosition (функция (позиция) {
document.getElementById ('data'). innerHTML = "широта:" + position.coords.latitude + "<br> долгота:" + position.coords.longitude;
});
}
navigator.geolocation
объекта navigator.geolocation
. Если это так, getCurrentPosition
метод getCurrentPosition
для этого объекта, который инициирует асинхронный запрос для позиции пользователя. Если запрос выполнен успешно, выполняется функция обратного вызова в методе. Эта функция осуществляет доступ к значениям объекта position
для широты и долготы с использованием точечной нотации и обновляет HTML.
Instructions
script
tags to check a user's current location and insert it into the HTML.
Tests
tests:
- text: Your code should use <code>navigator.geolocation</code> to access the user's current location.
testString: assert(code.match(/navigator\.geolocation\.getCurrentPosition/g));
- text: Your code should use <code>position.coords.latitude</code> to display the user's latitudinal location.
testString: assert(code.match(/position\.coords\.latitude/g));
- text: Your code should use <code>position.coords.longitude</code> to display the user's longitudinal location.
testString: assert(code.match(/position\.coords\.longitude/g));
- text: You should display the user's position within the <code>data</code> div element.
testString: assert(code.match(/document\.getElementById\(\s*?('|")data\1\s*?\)\.innerHTML/g));
Challenge Seed
<script>
// Add your code below this line
// Add your code above this line
</script>
<h4>You are here:</h4>
<div id="data">
</div>
Solution
// solution required