Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7d4631

Browse files
committed
closing #20
1 parent d9307f1 commit c7d4631

File tree

6 files changed

+94
-4
lines changed

6 files changed

+94
-4
lines changed

src/de.taimos.gpsd4java/src/de/taimos/gpsd4java/Tester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package de.taimos.gpsd4java;
1717

1818
import de.taimos.gpsd4java.api.ObjectListener;
19-
import de.taimos.gpsd4java.internal.backend.GPSdEndpoint;
19+
import de.taimos.gpsd4java.backend.GPSdEndpoint;
2020
import de.taimos.gpsd4java.types.DeviceObject;
2121
import de.taimos.gpsd4java.types.DevicesObject;
2222
import de.taimos.gpsd4java.types.PollObject;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright 2011 Thorsten Höger, Taimos GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package de.taimos.gpsd4java.api;
17+
18+
import de.taimos.gpsd4java.backend.GISTool;
19+
import de.taimos.gpsd4java.types.TPVObject;
20+
21+
/**
22+
*
23+
* created: 19.01.2011
24+
*
25+
*/
26+
public abstract class DistanceListener extends ObjectListener {
27+
28+
private TPVObject lastPosition;
29+
30+
private double threshold;
31+
32+
33+
/**
34+
* @param threshold the threshold to fire in kilometers
35+
*/
36+
public DistanceListener(double threshold) {
37+
this.threshold = threshold;
38+
}
39+
40+
@Override
41+
public void handleTPV(TPVObject tpv) {
42+
if ((this.lastPosition == null) || (GISTool.getDistance(tpv, this.lastPosition) > this.threshold)) {
43+
this.lastPosition = tpv;
44+
this.handleLocation(tpv);
45+
}
46+
}
47+
48+
protected abstract void handleLocation(TPVObject tpv);
49+
50+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package de.taimos.gpsd4java.backend;
2+
3+
import de.taimos.gpsd4java.types.TPVObject;
4+
5+
/**
6+
* @author thoeger
7+
*
8+
*/
9+
public class GISTool {
10+
11+
/**
12+
* @param c1
13+
* @param c2
14+
* @return distance in kilometers
15+
*/
16+
public static double getDistance(final TPVObject c1, final TPVObject c2) {
17+
return GISTool.getDistance(c1.getLongitude(), c2.getLongitude(), c1.getLatitude(), c2.getLatitude());
18+
}
19+
20+
/**
21+
* @param x1
22+
* @param x2
23+
* @param y1
24+
* @param y2
25+
* @return distance in kilometers
26+
*/
27+
public static double getDistance(double x1, double x2, double y1, double y2) {
28+
x1 = x1 * (Math.PI / 180);
29+
x2 = x2 * (Math.PI / 180);
30+
y1 = y1 * (Math.PI / 180);
31+
y2 = y2 * (Math.PI / 180);
32+
final double dlong = x1 - x2;
33+
final double dlat = y1 - y2;
34+
final double a = Math.pow(Math.sin(dlat / 2), 2) + Math.cos(y1) * Math.cos(y2) * Math.pow(Math.sin(dlong / 2), 2);
35+
final double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
36+
// Earth radius in kilometers
37+
return 6367 * c;
38+
}
39+
40+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* License for the specific language governing permissions and limitations under
1414
* the License.
1515
*/
16-
package de.taimos.gpsd4java.internal.backend;
16+
package de.taimos.gpsd4java.backend;
1717

1818
import java.io.BufferedReader;
1919
import java.io.BufferedWriter;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* License for the specific language governing permissions and limitations under
1414
* the License.
1515
*/
16-
package de.taimos.gpsd4java.internal.backend;
16+
package de.taimos.gpsd4java.backend;
1717

1818
import java.util.ArrayList;
1919
import java.util.List;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* License for the specific language governing permissions and limitations under
1414
* the License.
1515
*/
16-
package de.taimos.gpsd4java.internal.backend;
16+
package de.taimos.gpsd4java.backend;
1717

1818
import java.io.BufferedReader;
1919
import java.net.SocketException;

0 commit comments

Comments
 (0)