* fix(i18n): update Chinese translation of json apis and ajax * address comments Co-authored-by: Zhicheng Chen <chenzhicheng@dayuwuxian.com> Co-authored-by: S1ngS1ng <liuxing0514@gmail.com>
2.8 KiB
2.8 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(function(position) {
document.getElementById('data').innerHTML="latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude;
});
}
首先,它检查navigator.geolocation
对象是否存在。如果是,getCurrentPosition
则调用该对象上的方法,该方法启动对用户位置的异步请求。如果请求成功,则运行方法中的回调函数。此函数position
使用点表示法访问对象的纬度和经度值,并更新页面。
Instructions
script
标记内添加示例代码以检查用户的当前位置并将其插入 HTML
Tests
tests:
- text: 你的代码应该用于<code>navigator.geolocation</code>访问用户的当前位置。
testString: assert(code.match(/navigator\.geolocation\.getCurrentPosition/g));
- text: 你的代码应该用于<code>position.coords.latitude</code>显示用户的纬度位置。
testString: assert(code.match(/position\.coords\.latitude/g));
- text: 你的代码应该用于<code>position.coords.longitude</code>显示用户的经度位置。
testString: assert(code.match(/position\.coords\.longitude/g));
- text: 你应该在<code>data</code>div 元素中显示用户的位置。
testString: assert(code.match(/document\.getElementById\(\s*?('|")data\1\s*?\)\.innerHTML/g));
Challenge Seed
<script>
// 在这行下面添加代码
// 在这行上面添加代码
</script>
<h4>You are here:</h4>
<div id="data">
</div>
Solution
<script>
// Add your code below this line
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
document.getElementById('data').innerHTML = "latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude;
});
}
// Add your code above this line
</script>
<h4>You are here:</h4>
<div id="data">
</div>
</section>