hi,
thanks to tutorials from this community I managed to get Owntracks running on my setup. the position of two mobile phones is successfully shown in a google map when Im viewing basicUI from the local network. as soon as I
m remotely connected I see only my home location but no other devices.
the well known rule:
var PointType Matthias_moving_location
var PointType mhome = new PointType("41.xxxxxx,12.xxxxxx")//no spaces after comma
rule "Matthias Moving switch on"
when Item Matthias_moving received update ON
then
Matthias_moving_location = locationMatthias.state
logInfo("Matthias_moving_location updated","Matthias_moving_location set to" + Matthias_moving_location)
end
rule "MqttPostionParseMatthias"
when
Item mqttPositionMatthiasRaw changed
then
val String json = (mqttPositionMatthiasRaw.state as StringType).toString
val String type = transform("JSONPATH", "$._type", json)
if (type == "location") {
val String lat = transform("JSONPATH", "$.lat", json)
val String lon = transform("JSONPATH", "$.lon", json)
val String acc = transform("JSONPATH", "$.acc", json)
val String batt = transform("JSONPATH", "$.batt", json)
locationMatthias.postUpdate(new PointType(lat + "," + lon))
postUpdate(mqttMatthiasLatitude,lat)
postUpdate(mqttMatthiasLongitude,lon)
mqttMatthiasAccuracy.postUpdate(acc)
mqttMatthiasBattery.postUpdate(batt)
logInfo("mqtt", "location " + locationMatthias + " position")
MatthiasDistanceFromHome.postUpdate((mhome.distanceFrom(locationMatthias.state))*0.001) //meter in kilometer
}
if (Matthias_moving.state == ON){
if (Matthias_moving_location.distanceFrom(locationMatthias.state) > 300){
postUpdate(Matthias_moving, OFF)
}
}
end
the html file:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
<!--
.Flexible-container {
position: relative;
padding-bottom: 0px;
padding-top : 0px;
height : 345px ;
overflow: hidden;
}
.Flexible-container iframe,
.Flexible-container object,
.Flexible-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
-->
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places,drawing,geometry"></script>
<script type="text/javascript">
////////////////////////////////////////////////////////////////////////
// Google Maps JavaScript API:
// https://developers.google.com/maps/documentation/javascript/?hl=de
// Marker Icons:
// https://sites.google.com/site/gmapsdevelopment/
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// JQuery
////////////////////////////////////////////////////////////////////////
var map = null;
//make an empty bounds variable
var bounds = new google.maps.LatLngBounds();
// LatLng's we want to show
var latlngHome = new google.maps.LatLng("42.xxxxxx", "12.xxxxxx");
var latlngMatthias = new google.maps.LatLng("42.xxxxxx", "12.xxxxxx"); // initialize to home ...
var latlngDaniela = new google.maps.LatLng("42.xxxxxx", "12.xxxxxx"); // initialize to home ...
var map_options = { center : latlngHome,
zoom : 10,
mapTypeId : google.maps.MapTypeId.ROADMAP };
$( "#map_canvas" ).ready($(function() {
var map_canvas = document.getElementById('map_canvas');
map = new google.maps.Map(map_canvas, map_options)
var marker = new google.maps.Marker({
position : latlngHome,
map : map,
icon : 'http://maps.google.com/mapfiles/kml/pal2/icon10.png',
title : "Dahoam"
})
var circle = new google.maps.Circle({
center : latlngHome,
radius : 500,
map : map,
strokeColor : '#050505',
strokeOpacity : 0.5,
strokeWeight : 2,
fillColor : '#000000',
fillOpacity : 0,
}); // end of [Circle]
bounds.extend(latlngHome);
}))
$( document ).ready($(function() {
// ******************************************************************************
$.ajax({
url : "http://192.168.1.151:8080/rest/items/locationMatthias/state/",
data : {},
success : function( data ) {
if ( map == null) { return; }
if ( data == "Uninitialized") { return; }
var coords = data.split(',');
var latlngMatthias = new google.maps.LatLng(coords[0],coords[1]);
var marker = new google.maps.Marker({
position : latlngMatthias,
map : map,
icon : 'http://maps.google.com/mapfiles/ms/micons/man.png',
title : "Matthias"
}) // end of [Marker]
$.ajax({
url : "http://192.168.1.151:8080/rest/items/mqttMatthiasAccuracy/state/",
data : {},
success : function( data ) {
if ( data == "Uninitialized") { return; }
var accuracy = parseInt(data);
var circle = new google.maps.Circle({
center : latlngMatthias,
radius : accuracy,
map : map,
strokeColor : '#00FF00',
strokeOpacity : 0.8,
strokeWeight : 2,
fillColor : '#00FF00',
fillOpacity : 0.35,
}); // end of [Circle]
bounds.extend(latlngMatthias);
map.fitBounds(bounds);
} // end of [function]
}) // end of [$.ajax]
} // end of [function]
}) // end of [$.ajax]
// ******************************************************************************
$.ajax({
url : "http://192.168.1.151:8080/rest/items/locationDani/state/",
data : {},
success : function( data ) {
if ( map == null) { return; }
if ( data == "Uninitialized") { return; }
var coords = data.split(',');
var latlngDani = new google.maps.LatLng(coords[0],coords[1]);
var marker = new google.maps.Marker({
position : latlngDani,
map : map,
icon : 'http://maps.google.com/mapfiles/ms/micons/woman.png',
title : "Dani"
}) // end of [Marker]
$.ajax({
url : "http://192.168.1.151:8080/rest/items/mqttDaniAccuracy/state/",
data : {},
success : function( data ) {
if ( data == "Uninitialized") { return; }
var accuracy = parseInt(data);
var circle = new google.maps.Circle({
center : latlngDani,
radius : accuracy,
map : map,
strokeColor : '#00FF00',
strokeOpacity : 0.8,
strokeWeight : 2,
fillColor : '#00FF00',
fillOpacity : 0.35,
}); // end of [Circle]
bounds.extend(latlngDani);
map.fitBounds(bounds);
} // end of [function]
}) // end of [$.ajax]
} // end of [function]
}) // end of [$.ajax]
// ******************************************************************************
}))
</script>
</head>
<body>
<div id="map_canvas" class="Flexible-container" />
</body>
</html>
I can view http://192.168.1.151:8080/rest/items/locationMatthias/state and receive my location…
has somebody an idea why my locations are not routed through myopenhab?
thanks