-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetlocation1.php
187 lines (152 loc) · 4.79 KB
/
setlocation1.php
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
include_once 'Mapbox/header.php';
include 'Mapbox/locations_model.php';
include('func1.php');
//get_unconfirmed_locations();exit;
$con=mysqli_connect("localhost","root","","myhmsdb");
$patient = $_SESSION['pid'];
echo $patient;
?>
<style>
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
margin-left: 20%;
width:50%
}
#map { position:absolute;left: 700px; top:400px; bottom:0px;height:500px ;width:660px; }
.geocoder {
position:absolute;left: 800px; top:350px;
}
</style>
<h3 style="text-align:center">Set Your location by moving the market or use a search box.</h3>
<div class="container">
<form action="" id="signupForm">
<label for="lat">lat</label>
<input type="text" id="lat" name="lat" placeholder="Your lat..">
<label for="lng">lng</label>
<input type="text" id="lng" name="lng" placeholder="Your lng..">
<input type="submit" value="Submit" >
</form>
</div>
<div class="geocoder">
<div id="geocoder" ></div>
</div>
<div id="map"></div>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.48.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.48.0/mapbox-gl.css' rel='stylesheet' />
<style>
</style>
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.3.0/mapbox-gl-geocoder.min.js'></script>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.3.0/mapbox-gl-geocoder.css' type='text/css' />
<script>
var saved_markers = <?= get_saved_locations() ?>;
var user_location = [121,14];
mapboxgl.accessToken = 'pk.eyJ1IjoiYXNoZXIxMTAxIiwiYSI6ImNrcDBkbzViNjBmdGYyb28yb21meDMxdWYifQ.lqWKBOuKXCNxil9LmAh69w';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: user_location,
zoom: 10
});
// geocoder here
var geocoder = new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
// limit results to Australia
//country: 'IN',
});
var marker ;
// After the map style has loaded on the page, add a source layer and default
// styling for a single point.
map.on('load', function() {
addMarker(user_location,'load');
add_markers(saved_markers);
// Listen for the `result` event from the MapboxGeocoder that is triggered when a user
// makes a selection and add a symbol that matches the result.
geocoder.on('result', function(ev) {
alert("aaaaa");
console.log(ev.result.center);
});
});
map.on('click', function (e) {
marker.remove();
addMarker(e.lngLat,'click');
//console.log(e.lngLat.lat);
document.getElementById("lat").value = e.lngLat.lat;
document.getElementById("lng").value = e.lngLat.lng;
});
function addMarker(ltlng,event) {
if(event === 'click'){
user_location = ltlng;
}
marker = new mapboxgl.Marker({draggable: true,color:"#d02922"})
.setLngLat(user_location)
.addTo(map)
.on('dragend', onDragEnd);
}
function add_markers(coordinates) {
var geojson = (saved_markers == coordinates ? saved_markers : '');
console.log(geojson);
// add markers to map
geojson.forEach(function (marker) {
console.log(marker);
// make a marker for each feature and add to the map
new mapboxgl.Marker()
.setLngLat(marker)
.addTo(map);
});
}
function onDragEnd() {
var lngLat = marker.getLngLat();
document.getElementById("lat").value = lngLat.lat;
document.getElementById("lng").value = lngLat.lng;
console.log('lng: ' + lngLat.lng + '<br />lat: ' + lngLat.lat);
}
$('#signupForm').submit(function(event){
event.preventDefault();
var lat = $('#lat').val();
var lng = $('#lng').val();
var patient = '<?php echo $patient; ?>';
//var doctor = $('#doctor').val();
// var doctor = $doctor;
var url = 'Mapbox/locations_model1.php?add_location&lat=' + lat + '&lng=' + lng + '&patient=' + patient;
//var url = 'Mapbox/locations_model.php?add_location&lat=' + lat + '&lng=' + lng;
$.ajax({
url: url,
method: 'GET',
dataType: 'json',
success: function(data){
alert(data);
window.location = "admin-panel.php";
// location.reload();
}
});
});
document.getElementById('geocoder').appendChild(geocoder.onAdd(map));
</script>
<?php
include_once 'Mapbox/footer.php';
?>