coordonnées et zoom à renseigner dans la page trafic.html
actualisation toutes les 10 minutes ou par click sur la carte.
Code : Tout sélectionner
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
disableDefaultUI: true,
zoom: 14,
center: {lat: 48.0761279, lng: -1.7084094}
});
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
var marker = new google.maps.Marker({
position: {lat: 48.0761279, lng: -1.7084094},
map: map,
icon: 'http://google-maps-icons.googlecode.com/files/car.png',
title: 'miss'
});
marker.setMap(map);
setInterval(initMap, 600000);
}
Code : Tout sélectionner
$.ajax({
url: $.domoticzurl + "/json.htm?type=devices&rid=21"
}).done(function(data) {
var arrData = [];
$.each(data.result, function(i, item) {
var x = [item['Data']];
arrData.push(x);
});
var Myposition = arrData[1][1];
console.log(Myposition);
});Code : Tout sélectionner
function initMap() {
// define map area
var map = new google.maps.Map(document.getElementById('map'), {
disableDefaultUI: true,
zoom: 14,
center: {lat: 48.0761279, lng: -1.7084094}
});
// define traffic layer
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
// get olivier gps from variable
$.ajax({
url: [$.domoticzurl,'/json.htm?type=command¶m=getuservariable&idx=38'].join('')
}).done(function(data) {
if (typeof data.result !== 'undefined') {
var olivier = new google.maps.LatLng(parseFloat(data.result[0].Value.split(',')[0]),parseFloat(data.result[0].Value.split(',')[1]));
console.log('olivier: '+olivier);
// define olivier marker
var marker_olivier = new google.maps.Marker({
position: olivier,
map: map,
icon: 'http://maps.google.com/mapfiles/ms/micons/green-dot.png',
title: 'olivier'
});
// set marker
marker_olivier.setMap(map);
}
});
// get delphine gps from text sensor
$.ajax({
url: [$.domoticzurl,'/json.htm?type=devices&rid=21'].join('')
}).done(function(data) {
if (typeof data.result !== 'undefined') {
var delphine= new google.maps.LatLng(parseFloat(data.result[0].Data.split(',')[0]),parseFloat(data.result[0].Data.split(',')[1]));
console.log('delphine: '+delphine);
// define delphine marker
var marker_delphine = new google.maps.Marker({
position: delphine,
map: map,
icon: 'http://maps.google.com/mapfiles/ms/micons/pink-dot.png',
title: 'delphine'
});
// set marker
marker_delphine.setMap(map);
}
});
setInterval(initMap, 600000);
}
Code : Tout sélectionner
--~/domoticz/scripts/lua/script_time_localisation.lua
commandArray = {}
-- ==============================
-- Cherche la position iphone sur icloud
-- ==============================
--Uservariables
--- horaire de déclanchement
ReportHour=21
ReportMinute=00
ReportMinute2=15
ReportMinute3=30
ReportMinute4=45
--- User icloud
username = "XXXXXX.XXXXX@gmail.com"
--- Mdp icloud
password = "XXXXXXXXXX"
--- Nom de iphone / Ipad visible sous icloud
device = "iPhone de XXXXX"
--- Position de la maison
homelatitude = 46.34118765250665
homelongitude = -0.32796710729599
--- Périmètre de considération de la maison
skew = 0.003
--- IDX du device Text
idxText = '21'
-- Time to run?
time = os.date("*t")
--if time.hour == ReportHour and time.min == ReportMinute then
if time.min == ReportMinute or time.min == ReportMinute2 or time.min == ReportMinute3 or time.min == ReportMinute4 then
-- print('******************* Début du script *******************')
--- Faire un premier appel pour recherche la partition
--- Premiere URL pour rechercher la partition
UrlCloud1 = "curl -s -X POST -D - -o /dev/null -L -u '" .. username .. ":" .. password .. "' -H 'Content-Type: application/json; charset=utf-8' -H 'X-Apple-Find-Api-Ver: 2.0' -H 'X-Apple-Authscheme: UserIdGuest' -H 'X-Apple-Realm-Support: 1.0' -H 'User-agent: Find iPhone/1.3 MeKit (iPad: iPhone OS/4.2.1)' -H 'X-Client-Name: iPad' -H 'X-Client-UUID: 0cf3dc501ff812adb0b202baed4f37274b210853' -H 'Accept-Language: en-us' -H 'Connection: keep-alive' https://fmipmobile.icloud.com/fmipservice/device/" .. username .."/initClient"
local handle = io.popen(UrlCloud1)
local result = handle:read("*a")
handle:close()
--- Récupération de la partion dans le resultat de la premiere URL
stageserver = string.match(result, "X%-Apple%-MMe%-Host%:%s(.*%.icloud%.com)")
--- Faire la deuxième url en cherchant le nom du tel / ipad ou autre avec jq
UrlCloud2 = "curl -s -X POST -L -u '" .. username .. ":" .. password .. "' -H 'Content-Type: application/json; charset=utf-8' -H 'X-Apple-Find-Api-Ver: 2.0' -H 'X-Apple-Authscheme: UserIdGuest' -H 'X-Apple-Realm-Support: 1.0' -H 'User-agent: Find iPhone/1.3 MeKit (iPad: iPhone OS/4.2.1)' -H 'X-Client-Name: iPad' -H 'X-Client-UUID: 0cf3dc501ff812adb0b202baed4f37274b210853' -H 'Accept-Language: en-us' -H 'Connection: keep-alive' https://" .. stageserver .. "/fmipservice/device/" .. username .."/initClient | jq -r .content[].name,.content[].location.latitude,.content[].location.longitude"
local handle = io.popen(UrlCloud2)
-- Récupération des résultats posible plusieurs téléphone ou ipad
-- partie à optimiser avec fonction JQ
local count = 1
local lines = {}
while true do
local result = handle:read("*l")
if result == nil then break end
lines[count]=result
count = count + 1
end
handle:close()
-- Recherche du device et alimentation de l'interrupteur On/OFF dans Périmètre de considération de la maison
-- Alimentation de un device text de la longitude et latitude
-- partie à optimiser une fois que resultat optimisé
NbreTelephone = ((count-1)/3)
for i = 1, NbreTelephone do
if lines[i] == device then
if homelongitude - skew < tonumber(lines[i+(2*NbreTelephone)]) and homelongitude + skew > tonumber(lines[i+(2*NbreTelephone)]) and homelatitude - skew < tonumber(lines[i+NbreTelephone]) and homelatitude + skew > tonumber(lines[i+NbreTelephone]) then
commandArray['Geolocalisation_Richard']='On'
action = ('' .. (tonumber(lines[i+NbreTelephone])) ..','.. (tonumber(lines[i+(2*NbreTelephone)])) ..'')
commandArray['UpdateDevice']=idxText.."|0|"..action
else
commandArray['Geolocalisation_Richard']='Off'
action = ('' .. (tonumber(lines[i+NbreTelephone])) ..','.. (tonumber(lines[i+(2*NbreTelephone)])) ..'')
commandArray['UpdateDevice']=idxText.."|0|"..action
end
end
end
end
--Fin du script
return commandArrayCode : Tout sélectionner
$('#reload').click(function(){
initMap();
});