I know this is getting on a year old but Iām trying to make it work, So far Iāve failed but I canāt see what Iām doing wrong. Iām using GPSTracker which makes things significantly simpler and based on watching events.log the History Item is being populated correctly. Hereās what Iāve doneā¦
NOTE: Iām not using the gecoding API so I didnāt reproduce that Rule.
Preconditions
- GPSTracker installed and configured correctly.
- OwnTracks installed on phones and reporting to OH.
- Things created for each of the reporting phones and the Channels linked to Items.
Get Google Maps API Key
Navigate to https://developers.google.com/maps/documentation/embed/start and select āGet an API keyā on the left and follow the instructions. I already have a billing account. I chose the Maps JS API. Copy the key, we will need it later.
@sintei, it would be helpful if you posted exactly what you needed to change to get the Embedded API URL to work. I tried and failed.
Items
I created a few new Items.
Location vHome "Home Location"
String vMaps_API "Google Maps API Key"
Group:String LocationHistories
Group:Location Locations
// Rich
Location vRich_Location "Rich's Current Lat/Lon [%s]"
<motion> (gChart, Locations)
{ channel="gpstracker:tracker:RK:lastLocation" }
Number vRich_Phone_Battery "Rich's Phone Battery [%d %%]"
<battery>
{ channel="gpstracker:tracker:RK:batteryLevel" }
DateTime vRich_Last_GPS "Rich's Last Location Report [%1$tm/%1$td %1$tH:%1$tM]"
<time>
{ channel="gpstracker:tracker:RK:lastReport" }
Number:Length vRich_GPS_Accuracy "Rich's Location Accuracy [%d ft]"
<motion>
{ channel="gpstracker:tracker:RK:gpsAccuracy" }
String vRich_Region "Rich's Location [%s]"
<motion>
Number:Length vRich_Distance "Rich's Distance from Home [%.1f mi]"
<motion>
{ channel="gpstracker:tracker:RK:distanceSystem" }
String vRich_Location_History
(LocationHistories)
// Jenn
Location vJenn_Location "Jenn's Current Lat/Lon [%s]"
<motion> (gChart, Locations)
{ channel="gpstracker:tracker:JC:lastLocation" }
Number vJenn_Phone_Battery "Jenn's Phone Battery [%d %%]"
<battery>
{ channel="gpstracker:tracker:JC:batteryLevel" }
DateTime vJenn_Last_GPS "Jenn's Last Location Report [%1$tm/%1$td %1$tH:%1$tM]"
<time>
{ channel="gpstracker:tracker:JC:lastReport" }
Number:Length vJenn_GPS_Accuracy "Jenn's Location Accuracy [%d ft]"
<motion>
{ channel="gpstracker:tracker:JC:gpsAccuracy" }
String vJenn_Region "Jenn's Location [%s]"
<motion>
Number:Length vJenn_Distance "Jenn's Distance from Home [%.1f mi]"
<motion>
{ channel="gpstracker:tracker:JC:distanceSystem" }
String vJenn_Location_History
(LocationHistories)
Rules
I use Python but these are simple enough they should be understood by all. Because the GPSTracker handles parsing the messages from OwnTracks and Iām not doing geocoding yet so all I need to do is update the history Items.
@rule("Clear Histories",
description="Clears location histories",
tags=["location"])
@when("Time cron 0 0 0 ? * * *")
def clear_hist(event):
for loc in ir.getItems("LocationHistories").members:
events.postUpdate(loc.name, "")
@rule("Location Changed",
description="Updates location history",
tags=["location"])
@when("Member of Locations changed")
def loc_changed(event):
hist_item = "{}_History".format(event.itemName)
events.postUpdate(hist_item, "{}{};".format(items[hist_item], event.itemState))
Watching events.log, my History Item is updating as expected:
<lat>,<lon>;<lat>,<lon>;
No spaces. NOTE that I had to initialize the History Item to āā. I need to update the code to handle that case, but I mention it here. Without initializing the Item it ends up starting with NULL
.
Webview
Downloaded and change the name and unzip map.zip.txt from Google Map. Unzip this folder to $OH_CONF/html. Made the following edits:
index.html
-
Change the lang attribute at the top to āenā.
-
Change the error message āPositionsdaten sind nicht geladen.ā to āPosition data is not loaded.ā
-
Inserted my API Key where indicated at the bottom of the file and change the end of the URL to initMap
instead of initialize
. The example URL on Googleās site uses initMap
. It doesnāt work either way sadly. ![:frowning: :frowning:](https://community.openhab.org/images/emoji/twitter/frowning.png?v=9)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Force latest IE rendering engine & Chrome Frame -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="Displays the current user locations and the location history data in Google-Maps.">
<meta name="author" content="Patrik Gfeller">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Positionsinformationen</title>
<link href="./css/style.css" type="text/css" rel="stylesheet">
<script src="./lib/openHAB.js"></script>
<script src="./lib/map20.js"></script>
</head>
<body>
<main>
<div id="map" class="map">
<span id="errorMessage" class="errorMessage">Position data is not loaded.</span>
</div>
</main>
<!-- Google-Maps API must be loaded after DOM is initialized completely. -->
<script
src="https://maps.googleapis.com/maps/api/js?key=<MY API KEY>&callback=initMap"
async defer></script>
</body>
</html>
lib/map21.js
Populated openHABLocations with my Items.
I check that the Items are populated properly but whenever I load the page I get the āPosition data is not loaded.ā error. Iāve double checked for typos everywhere I can think of to no avail. Everything
var openHABLocations = {
"Home": {
locationItem: "vHome",
locationIcon: "./img/home.png",
locationType: locationTypes.home,
animation: null,
historyItem: undefined,
historyIcon: undefined,
zIndex: 10
},
"Rich": {
locationItem: "vRich_Location",
locationIcon: "./img/patrik.png",
locationType: locationTypes.user,
animation: google.maps.Animation.DROP,
historyItem: "vRich_Location_History",
historyIcon: "./img/historyPatrik.png",
zIndex: 9
},
"Jenn": {
locationItem: "vJenn_Location",
locationIcon: "./img/karin.png",
locationType: locationTypes.user,
animation: google.maps.Animation.DROP,
historyItem: "vJenn_Location_History",
historyIcon: "./img/historyKarin.png",
zIndex: 8
}
};
Any assistance or information telling me this no longer works would be appreciated.