-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocation.html
99 lines (85 loc) · 2.73 KB
/
location.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<html>
<head>
<title>Welcome to nginx!</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<script
type="text/javascript"
src="https://api.map.baidu.com/api?v=2.0&ak=221c0dc4311a5b793f4b12d5aad60ac9"
></script>
<style></style>
</head>
<body>
<h2>测试 h5 定位</h2>
<button id="find-me">navigator.geolocation.getCurrentPosition</button><br />
<p id="status"></p>
<p id="map-link"></p>
<h2>测试 webview 定位</h2>
<button onclick="getLocation()">navigator.geolocation.watchPosition</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
getLocation();
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = `纬度:${position.coords.latitude} °,经度:${position.coords.longitude} °`;
}
</script>
<h2>测试上传</h2>
<input
id="fileElem"
type="file"
size="38"
name="fileToUpload"
class="input_pic"
accept="image/jpeg, image/png"
/>
<script>
document
.querySelector("#fileElem")
.addEventListener("change", onFileChange);
// 上传文件
function onFileChange(e) {
var vm = this;
var files = e.target.files || e.dataTransfer.files;
if (!files.length) return;
var file = files[0];
console.log(file);
}
</script>
</body>
<script>
geoFindMe();
function geoFindMe() {
const status = document.querySelector("#status");
const mapLink = document.querySelector("#map-link");
mapLink.href = "";
mapLink.textContent = "";
function success(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
status.textContent = "";
mapLink.href = `https://www.openstreetmap.org/#map=18/${latitude}/${longitude}`;
mapLink.textContent = `纬度:${latitude} °,经度:${longitude} °`;
}
function error() {
status.textContent = "无法获取你的位置";
}
if (!navigator.geolocation) {
status.textContent = "你的浏览器不支持地理位置";
} else {
status.textContent = "定位中……";
navigator.geolocation.getCurrentPosition(success, error);
}
}
document.querySelector("#find-me").addEventListener("click", geoFindMe);
</script>
</html>