You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
293 lines
8.5 KiB
293 lines
8.5 KiB
<!doctype html>
|
|
<html lang="en">
|
|
|
|
<!-- 主頁header -->
|
|
<?php
|
|
|
|
/*--- 處理session ----*/
|
|
include "include-session-security.php"; #確認session
|
|
/*
|
|
if(isset($_SESSION['user_id'])){
|
|
#echo $_SESSION['user_id'];
|
|
$customerid = $_SESSION['user_id'];
|
|
}
|
|
*/
|
|
/*--- 處理session ----*/
|
|
|
|
#$customerid = "A000000001";
|
|
|
|
include "include-header.php";
|
|
|
|
$latitude = $_REQUEST["latitude-input"];
|
|
$longitude = $_REQUEST["longitude-input"];
|
|
|
|
//echo $latitude . "<br>";
|
|
//echo $longitude . "<br>";
|
|
//echo $user_id . "<br>";
|
|
|
|
|
|
|
|
$off_line_time = 18000; #預設不可離線 30 mins
|
|
|
|
require_once "db/database.php"; # 載入db.php來連結資料庫
|
|
$data = array(); # 設置一個空陣列來放資料is
|
|
$sql = "SELECT * FROM account where (accountid = '$user_id')"; # sql語法存在變數中
|
|
$data = mysqli_query($link,$sql); # 用mysqli_query方法執行(sql語法)將結果存在變數中
|
|
foreach($data as $data){
|
|
$accounttype = $data['accounttype'];
|
|
$name = $data['name'];
|
|
}
|
|
if ((strlen($accounttype) != 0) and ($accounttype == 'B')){ #保養員屬性才將位置存入
|
|
#echo "<br> pid: " . $pid;
|
|
#echo "<br> accounttype: " . $accounttype;
|
|
#echo "<br> account: " . $account;
|
|
#echo "<br> name: " . $name;
|
|
#echo "<br> update_time: " . date('Y-m-d H:i:s');
|
|
$upload_time = date('Y-m-d H:i:s');
|
|
$sql = "UPDATE location_last set name = '$name', latitude = '$latitude', longitude = '$longitude', upload_time = '$upload_time' WHERE account_id='$user_id'";
|
|
mysqli_query($link,$sql); # 用mysqli_query方法執行(sql語法)將結果存在變數中
|
|
|
|
$sql_1 = "INSERT INTO location_log (account_id, name, latitude, longitude, upload_time) values " .
|
|
"('$user_id', '$name', '$latitude', '$longitude', '$upload_time')";
|
|
mysqli_query($link,$sql_1); # 用mysqli_query方法執行(sql語法)將結果存在變數中
|
|
}
|
|
|
|
/*
|
|
$j=0; #{text:顯示文字, color:顏色}
|
|
$lat_sum=0;
|
|
$lng_sum=0;
|
|
$lat_center=0 ;
|
|
$lng_center=0 ;
|
|
$latitude_array = array();
|
|
$longitude_array = array();
|
|
foreach($data as $data){
|
|
$j = $j + 1;
|
|
if ($j <> count($data)){
|
|
echo "{label:'" . $data['name'] . "',lat:" . $data['latitude'] . ",lng:" . $data['longitude'] . "},";
|
|
}else{
|
|
echo "{label:'" . $data['name'] . "',lat:" . $data['latitude'] . ",lng:" . $data['longitude'] . "}";
|
|
}
|
|
$lat_sum = $lat_sum + $data['latitude'];
|
|
$lng_sum = $lng_sum + $data['longitude'];
|
|
array_push($latitude_array, $data['latitude']);
|
|
array_push($longitude_array, $data['longitude']);
|
|
}
|
|
$lat_center=$lat_sum / $j;
|
|
$lng_center=$lng_sum / $j;
|
|
print_r($latitude_array);
|
|
print_r($longitude_array);
|
|
echo max($latitude_array) . min($latitude_array);
|
|
echo max($longitude_array) . min($longitude_array);
|
|
*/
|
|
|
|
/*
|
|
foreach($data as $data){
|
|
echo $data['facilityno'] . "-" . $data['contractno'] . "-". $data['repairerid'] . "-". $data['repairername'] . "-". "<br>";
|
|
}
|
|
*/
|
|
|
|
?>
|
|
<!-- * 主頁header -->
|
|
|
|
<style>
|
|
html,
|
|
body {
|
|
height: 100%;
|
|
width: 100%;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
#map {
|
|
height: 600px;
|
|
width: 100%;
|
|
background: #000;
|
|
}
|
|
</style>
|
|
|
|
<body>
|
|
|
|
<!-- loader -->
|
|
<div id="loader">
|
|
<div class="spinner-border text-primary" role="status"></div>
|
|
</div>
|
|
<!-- * loader -->
|
|
|
|
<!-- App Header -->
|
|
<div class="appHeader bg-primary text-light">
|
|
<!--
|
|
<div class="left">
|
|
<a href="javascript:;" class="headerButton goBack">
|
|
<ion-icon name="chevron-back-outline"></ion-icon>
|
|
</a>
|
|
</div>
|
|
-->
|
|
<div class="pageTitle">現在位置</div>
|
|
<!--
|
|
<div class="right">
|
|
</div>
|
|
-->
|
|
</div>
|
|
<!-- * App Header -->
|
|
|
|
<!-- App Capsule -->
|
|
<div id="appCapsule">
|
|
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
|
|
<!-- Simple Multi Listview -->
|
|
<div id="map"></div>
|
|
<script>
|
|
var map;
|
|
var marker;
|
|
function initMap() {
|
|
var position = {
|
|
lat: <?php echo $latitude; ?>,
|
|
lng: <?php echo $longitude; ?>
|
|
};
|
|
map = new google.maps.Map(document.getElementById('map'), {
|
|
zoom: 18,
|
|
center: position,
|
|
mapTypeControl:true,
|
|
fullscreenControl:true,
|
|
rotateControl:true,
|
|
scaleControl:true,
|
|
streetViewControl:true,
|
|
zoomControl:true,
|
|
mapTypeControlOptions:{position:google.maps.ControlPosition.TOP_CENTER},
|
|
fullscreenControlOptions:{position:google.maps.ControlPosition.TOP_RIGHT},
|
|
rotateControlOptions:{position:google.maps.ControlPosition.RIGHT_CENTER},
|
|
scaleControlOptions:{position:google.maps.ControlPosition.RIGHT_BOTTOM},
|
|
streetViewControlOptions:{position:google.maps.ControlPosition.TOP_LEFT},
|
|
zoomControlOptions:{position:google.maps.ControlPosition.RIGHT_BOTTOM}
|
|
});
|
|
marker = new google.maps.Marker({
|
|
position: position,
|
|
map: map,
|
|
label: '<?php echo $name; ?>',
|
|
animation: google.maps.Animation.BOUNCE //marker跳動
|
|
});
|
|
}
|
|
|
|
function updateContent() {
|
|
console.log('开始更新');
|
|
// 获取当前位置
|
|
|
|
if (navigator.geolocation) {
|
|
navigator.geolocation.getCurrentPosition(function (position) { //位置移动后,多次获取定位
|
|
var positiondata = {
|
|
lat: position.coords.latitude,
|
|
lng: position.coords.longitude
|
|
};
|
|
// 自定义点标记内容
|
|
if(positiondata.lat!=''){
|
|
//ajax提交数据
|
|
var urll = location.href;
|
|
var wurl = urll.split('app')[0];
|
|
var URL = wurl + 'app/api-location-autosubmit.php';
|
|
console.log(URL);
|
|
$.ajax({
|
|
method: 'post',
|
|
url: URL,
|
|
data: {
|
|
latitude:position.coords.latitude,
|
|
longitude:position.coords.longitude,
|
|
token:'<?php echo $_REQUEST["token"]; ?>'
|
|
},
|
|
success: function (data) {
|
|
console.log('返回的结果');
|
|
console.log(data);
|
|
res=eval("("+data+")");
|
|
if(res.code=='200'){
|
|
console.log('开始更新标记位置');
|
|
console.log(positiondata);
|
|
marker.setPosition(positiondata);
|
|
marker.setLabel('位置变了');
|
|
marker.setMap(map);
|
|
}else{
|
|
console.log("提交失败");
|
|
}
|
|
|
|
|
|
}
|
|
});
|
|
|
|
|
|
}else{
|
|
alert('获取坐标失败');
|
|
}
|
|
})
|
|
}else{
|
|
console.log('不支持获取定位');
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
setInterval("updateContent()", 20000); //每隔20秒执行一次
|
|
|
|
|
|
</script>
|
|
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDCJp-JIcYIyeR_QNpREvsepApvVytZWOs&callback=initMap" async defer></script>
|
|
|
|
<style>
|
|
#info {
|
|
position: fixed;
|
|
z-index: 999;
|
|
bottom: 20px;
|
|
left: 0px;
|
|
background: #222;
|
|
padding: 20px 30px;
|
|
color: #fff;
|
|
box-shadow: rgba(0, 0, 0, .5) 0 0 10px;
|
|
border-radius: 0 5px 5px 0;
|
|
}
|
|
|
|
#info a {
|
|
color: #0bf;
|
|
transition: .2s;
|
|
}
|
|
|
|
#info a:hover {
|
|
color: #6df;
|
|
}
|
|
</style>
|
|
<!-- <div id="info">相關參考:<a id="infoLink" href="#" target="_blank"></a></div> -->
|
|
<script>
|
|
var href = location.href;
|
|
var page = href.split("demo/");
|
|
var name = page[1].split("-demo")[0];
|
|
var title = document.querySelector('title').innerHTML;
|
|
document.getElementById('infoLink').setAttribute('href', '/articles/' + name + '.html');
|
|
document.getElementById('infoLink').innerHTML = title.split("demo")[0];
|
|
</script>
|
|
<!-- * Simple Multi Listview -->
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
<!-- * App Capsule -->
|
|
|
|
<!-- 主頁頁尾 -->
|
|
<?php
|
|
include "include-footer.php";
|
|
mysqli_close($link); #代表結束連線
|
|
?>
|
|
<!-- * 主頁頁尾 -->
|
|
|
|
<!-- 主頁頁尾按鈕 -->
|
|
<?php
|
|
# include "include-bottom-menu.php";
|
|
?>
|
|
<!-- * 主頁頁尾按鈕 -->
|
|
|
|
<!-- ///////////// Js Files //////////////////// -->
|
|
<!-- Jquery -->
|
|
<?php
|
|
include "include-jsfiles.php";
|
|
?>
|
|
|
|
</body>
|
|
|
|
</html>
|