Hello, guys. I`m trying to dynamically represent the changes of coordinates of a groovy domain object via Google Maps API. The object has fields:
Double lat
Double lng
and a method:
void flyTo(lat, lng){
Thread.start(){
while (locked){
changeCoords (this)
this.save()
}
}
and here is a JS to repopulate changes to the map every 5 seconds:
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key="MY_API_KEY"
type="text/javascript"></script>
<script type="text/javascript">
var usCenterPoint = new GLatLng(39.833333, -98.583333)
var usZoom = 4
var map = new GMap2(document.getElementById("map"))
function load() {
if (GBrowserIsCompatible()) {
var latFrom = -900;
var latTo = -900;
var lngFrom = -900;
var lngTo = -900;
map.setCenter(usCenterPoint, usZoom)
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
updateMap();
}
}
function updateMap(){
map.clearOverlays();
<g:each in="${dronesList}" status="i" var="drone">
var point${drone.id} = new GLatLng(${drone.lat}, ${drone.lng})
if (latFrom == -900){
latFrom = ${drone.lat}
lngFrom = ${drone.lng}
} else {
latTo = ${drone.lat}
lngTo = ${drone.lng}
}
var marker${drone.id} = new GMarker(point${drone.id})
marker${drone.id}.bindInfoWindowHtml("<strong>${drone.name}</strong><br/>${drone.description}<br/>")
map.addOverlay(marker${drone.id});
// map.setCenter(point${drone.id},usZoom);
if (latTo != -900){
var polyline = new GPolyline([
new GLatLng(latFrom, lngFrom),
new GLatLng(latTo, lngTo)
], "#ff0000", 10);
map.addOverlay(polyline);
}
</g:each>
}
</script>
</head>
<body onload="load(); setInterval('updateMap()', 5000)" onunload="GUnload()">
When I start an execution of a flyTo()
method, I'm getting two bugs.
- The changes of the object are not populated. In fact, the map does not even show up.
- I'm getting an exception in thread when I call a
this.save()
method:No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
How do I resolve those? Is there a better way to do this?