Skip to content

Commit

Permalink
Fix reverse geocoding (fix traccar#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Aug 12, 2012
1 parent ff01e06 commit afa255e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<!-- Web interface port -->
<entry key="http.enable">true</entry>
<entry key="http.port">8082</entry>

<entry key="geocoder.enable">true</entry>

<!-- Logging options -->
<entry key="logger.enable">true</entry>
Expand Down
16 changes: 11 additions & 5 deletions src/org/traccar/ReverseGeocoderHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,14 +37,19 @@ public ReverseGeocoderHandler(ReverseGeocoder geocoder) {
}

@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;
}

}
2 changes: 1 addition & 1 deletion src/org/traccar/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public String format(LogRecord record) {
}

private void initGeocoder(Properties properties) throws IOException {
if (Boolean.parseBoolean("geocoder.enable")) {
if (Boolean.parseBoolean(properties.getProperty("geocoder.enable"))) {
geocoder = new GoogleReverseGeocoder();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/org/traccar/TrackerEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
", longitude: " + position.getLongitude() +
", altitude: " + position.getAltitude() +
", speed: " + position.getSpeed() +
", course: " + position.getCourse());
", course: " + position.getCourse() +
", power: " + position.getPower());
}

// Write position to database
Expand Down

0 comments on commit afa255e

Please sign in to comment.