forked from Esri/jquery-mobile-map-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
140 lines (118 loc) · 4.75 KB
/
index.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Basic jQuery Mobile Map</title>
<link rel="stylesheet" type="text/css" href="css/themes/black-theme.min.css"/>
<link rel="stylesheet" type="text/css" href="css/themes/jquery.mobile.icons.min.css"/>
<link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.12/esri/css/esri.css"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" />
<style type="text/css">
html,body, div[data-role ="page"] {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
overflow: hidden !important;
font-size: 20px;
}
.ui-header{
margin: 0px !important;
padding: 0px !important;
float: left;
}
.ui-content{
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
#mapDiv {
position: absolute;
background-color: #EEEEDD;
height: 100%;
width: 100%;
padding: 0px;
z-index: 0;
left: 0px;
}
</style>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script>
</head>
<body>
<div data-role="page" id="home">
<div data-theme="b" data-role="header" data-position="fixed">
<h3>HTML5 Geolocation</h3>
</div>
<div data-role="content">
<div id="mapDiv"></div>
</div>
<script type="text/javascript">
$( '#home' ).on( 'pagecreate',function(event){
jqueryInit();
});
</script>
</div>
<script src="src/jQueryHelper.js"></script>
<script type="text/javascript" src="//js.arcgis.com/3.13/"></script>
<script>
var map;
function jqueryInit(){
require(["esri/map","esri/symbols/PictureMarkerSymbol","dojo/on","dojo/domReady!"],
function(Map,PictureMarkerSymbol,on) {
var helper = null;
// Create map
map = new Map("mapDiv",{
basemap: "streets",
center: [-98.5,39.8],
zoom: 4
});
// Wait until map has loaded before starting geolocation
map.on("load",init);
// Create the marker symbol
var markerSymbol = new PictureMarkerSymbol({
"angle":0,
"xoffset":0,
"yoffset":0,
"type":"esriPMS",
"url":"images/green-pin.png",
"width":35,
"height":35
})
function init(){
try{
helper = new jQueryHelper(map);
}
catch(err) {
console.log("Unable to initialize jQueryHelper: " + err.message);
}
map.reposition();
map.resize();
startGeolocation();
}
function startGeolocation(){
navigator.geolocation.getCurrentPosition(locationSuccess,locationError,{setHighAccuracy:true});
}
// Handle location success
function locationSuccess(position){
if(position.coords.latitude != null || position.coords.longitude != null){
console.log("ps " + position.coords.longitude + ", " + position.coords.latitude)
var wgsPt = new esri.geometry.Point(position.coords.longitude,position.coords.latitude);
map.graphics.add(new esri.Graphic(wgsPt, markerSymbol));
map.centerAndZoom(wgsPt,9);
//Set jQueryHelper properties
helper.setCenterPt(position.coords.latitude,position.coords.longitude,4326);
helper.setZoom(9);
}
}
function locationError(err){
console.log("locationError: " + err.message);
}
}
);
}
</script>
</body>
</html>