From bb94a3d09a78530807cab31d2b0cee829ff084d4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 20 Jan 2014 19:00:40 +1300 Subject: Fix list geocoding issue (fix #520) --- src/org/traccar/ReverseGeocoderHandler.java | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/org/traccar/ReverseGeocoderHandler.java b/src/org/traccar/ReverseGeocoderHandler.java index 74dfd10e9..8bdd7ebfc 100644 --- a/src/org/traccar/ReverseGeocoderHandler.java +++ b/src/org/traccar/ReverseGeocoderHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package org.traccar; +import java.util.List; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; @@ -22,15 +23,9 @@ 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 OneToOneDecoder { - /** - * Geocoder object - */ - private ReverseGeocoder geocoder; + private final ReverseGeocoder geocoder; public ReverseGeocoderHandler(ReverseGeocoder geocoder) { this.geocoder = geocoder; @@ -40,12 +35,18 @@ public class ReverseGeocoderHandler extends OneToOneDecoder { protected Object decode( ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { - - if (msg instanceof Position) { - Position position = (Position) msg; - if (geocoder != null) { + + if (geocoder != null) { + if (msg instanceof Position) { + Position position = (Position) msg; position.setAddress(geocoder.getAddress( position.getLatitude(), position.getLongitude())); + } else if (msg instanceof List) { + List positions = (List) msg; + for (Position position : positions) { + position.setAddress(geocoder.getAddress( + position.getLatitude(), position.getLongitude())); + } } } -- cgit v1.2.3