From afa255e4c319482a486230308214374afe842bb8 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 12 Aug 2012 13:28:41 +0400 Subject: Fix reverse geocoding (fix #37) --- src/org/traccar/ReverseGeocoderHandler.java | 16 +++++++++++----- src/org/traccar/Server.java | 2 +- src/org/traccar/TrackerEventHandler.java | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/org/traccar/ReverseGeocoderHandler.java b/src/org/traccar/ReverseGeocoderHandler.java index a7123bcec..74dfd10e9 100644 --- a/src/org/traccar/ReverseGeocoderHandler.java +++ b/src/org/traccar/ReverseGeocoderHandler.java @@ -15,16 +15,17 @@ */ package org.traccar; +import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; -import org.jboss.netty.channel.SimpleChannelHandler; +import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.geocode.ReverseGeocoder; import org.traccar.model.Position; /** * Reverse geocoding channel event handler */ -public class ReverseGeocoderHandler extends SimpleChannelHandler { +public class ReverseGeocoderHandler extends OneToOneDecoder { /** * Geocoder object @@ -36,14 +37,19 @@ public class ReverseGeocoderHandler extends SimpleChannelHandler { } @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { - if (e.getMessage() instanceof Position) { - Position position = (Position) e.getMessage(); + protected Object decode( + ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + + if (msg instanceof Position) { + Position position = (Position) msg; if (geocoder != null) { position.setAddress(geocoder.getAddress( position.getLatitude(), position.getLongitude())); } } + + return msg; } } diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 5a6b298c7..2f1c7fce5 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -174,7 +174,7 @@ public class Server { } private void initGeocoder(Properties properties) throws IOException { - if (Boolean.parseBoolean("geocoder.enable")) { + if (Boolean.parseBoolean(properties.getProperty("geocoder.enable"))) { geocoder = new GoogleReverseGeocoder(); } } diff --git a/src/org/traccar/TrackerEventHandler.java b/src/org/traccar/TrackerEventHandler.java index e4e45a174..9e46372ca 100644 --- a/src/org/traccar/TrackerEventHandler.java +++ b/src/org/traccar/TrackerEventHandler.java @@ -55,7 +55,8 @@ public class TrackerEventHandler extends SimpleChannelHandler { ", longitude: " + position.getLongitude() + ", altitude: " + position.getAltitude() + ", speed: " + position.getSpeed() + - ", course: " + position.getCourse()); + ", course: " + position.getCourse() + + ", power: " + position.getPower()); } // Write position to database -- cgit v1.2.3