diff --git a/CodenameOne/src/com/codename1/location/LatLng.java b/CodenameOne/src/com/codename1/location/LatLng.java
new file mode 100644
index 0000000000..c67c193199
--- /dev/null
+++ b/CodenameOne/src/com/codename1/location/LatLng.java
@@ -0,0 +1,37 @@
+package com.codename1.location;
+
+public interface LatLng {
+
+ public void setLatitude(double latitude);
+
+ public void setLongitude(double longitude);
+
+ public double getLatitude();
+
+ public double getLongitude();
+
+// @Override
+// public int hashCode() {
+// final int prime = 31;
+// int result = 1;
+// long temp;
+// temp = Double.doubleToLongBits(this.getLatitude());
+// result = prime * result + (int) (temp ^ (temp >>> 32));
+// temp = Double.doubleToLongBits(this.getLongitude());
+// result = prime * result + (int) (temp ^ (temp >>> 32));
+// return result;
+// }
+//
+// @Override
+// public boolean equals(Object object) {
+// if (this == object)
+// return true;
+// if (object == null)
+// return false;
+// if (!(object instanceof LatLng))
+// return false;
+// LatLng aPosition = (LatLng) object;
+// return (aPosition.getLatitude()==this.getLatitude() && aPosition.getLongitude()==this.getLongitude());
+// //return (Double.doubleToLongBits(aPosition.getLatitude())==Double.doubleToLongBits(this.getLatitude()) && Double.doubleToLongBits(aPosition.getLongitude())==Double.doubleToLongBits(this.getLongitude()));
+// }
+}
diff --git a/CodenameOne/src/com/codename1/location/Location.java b/CodenameOne/src/com/codename1/location/Location.java
index e4067497c5..66bac0c45a 100644
--- a/CodenameOne/src/com/codename1/location/Location.java
+++ b/CodenameOne/src/com/codename1/location/Location.java
@@ -44,7 +44,7 @@
*
The sample below demonstrates the usage of the background geofencing API:
*
*/
-public class Location {
+public class Location implements LatLng {
private int status;
@@ -222,7 +222,7 @@ public void setVelocity(float velocity) {
* @param l2 The location to measure distance to.
* @return The number of metres between the current location and {@literal l2}.
*/
- public double getDistanceTo(Location l2) {
+ public double getDistanceTo(LatLng l2) {
return haversine(getLatitude(), getLongitude(), l2.getLatitude(), l2.getLongitude()) * 1000;
}
@@ -255,10 +255,10 @@ public String toString() {
* location.
* @return
*/
- public Comparator createDistanceCompartor() {
- return new Comparator() {
+ public Comparator createDistanceCompartor() {
+ return new Comparator() {
- public int compare(Location o1, Location o2) {
+ public int compare(LatLng o1, LatLng o2) {
double d1 = Location.this.getDistanceTo(o1);
double d2 = Location.this.getDistanceTo(o2);
return d1 < d2 ? -1 : d2 < d1 ? 1 : 0;
@@ -274,9 +274,59 @@ public int compare(Location o1, Location o2) {
* @param l
* @return True if l has same latitude and longitude as this location.
*/
- boolean equalsLatLng(Location l) {
+ boolean equalsLatLng(LatLng l) {
+ return l != null && l.getLatitude() == latitude && l.getLongitude() == longitude;
+ }
- return l != null && l.latitude == latitude && l.longitude == longitude;
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Float.floatToIntBits(accuracy);
+ long temp;
+ temp = Double.doubleToLongBits(altitude);
+ result = prime * result + (int) (temp ^ (temp >>> 32));
+ result = prime * result + Float.floatToIntBits(direction);
+ temp = Double.doubleToLongBits(latitude);
+ result = prime * result + (int) (temp ^ (temp >>> 32));
+ temp = Double.doubleToLongBits(longitude);
+ result = prime * result + (int) (temp ^ (temp >>> 32));
+ result = prime * result + status;
+ result = prime * result + (int) (timeStamp ^ (timeStamp >>> 32));
+ result = prime * result + Float.floatToIntBits(velocity);
+ return result;
+ }
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Location other = (Location) obj;
+ if (Float.floatToIntBits(accuracy) != Float.floatToIntBits(other.accuracy))
+ return false;
+ if (Double.doubleToLongBits(altitude) != Double.doubleToLongBits(other.altitude))
+ return false;
+ if (Float.floatToIntBits(direction) != Float.floatToIntBits(other.direction))
+ return false;
+ if (Double.doubleToLongBits(latitude) != Double.doubleToLongBits(other.latitude))
+ return false;
+ if (Double.doubleToLongBits(longitude) != Double.doubleToLongBits(other.longitude))
+ return false;
+ if (status != other.status)
+ return false;
+ if (timeStamp != other.timeStamp)
+ return false;
+ if (Float.floatToIntBits(velocity) != Float.floatToIntBits(other.velocity))
+ return false;
+ return true;
+ }
+
+
+
+
}
diff --git a/CodenameOne/src/com/codename1/maps/BoundingBox.java b/CodenameOne/src/com/codename1/maps/BoundingBox.java
index c5239cd411..22597e4ddc 100644
--- a/CodenameOne/src/com/codename1/maps/BoundingBox.java
+++ b/CodenameOne/src/com/codename1/maps/BoundingBox.java
@@ -21,6 +21,8 @@
import java.util.Vector;
+import com.codename1.location.LatLng;
+
/**
* This class declares a bounding box of coordinates on the map.
*
@@ -95,7 +97,7 @@ public double longitudeDifference() {
* @param cur coordinate to check
* @return true if the given coordinate is contained in the bounding box
*/
- public boolean contains(Coord cur) {
+ public boolean contains(LatLng cur) {
double latitude = cur.getLatitude();
if (latitude > getNorthEast().getLatitude() || latitude < getSouthWest().getLatitude()) {
return false;
diff --git a/CodenameOne/src/com/codename1/maps/Coord.java b/CodenameOne/src/com/codename1/maps/Coord.java
index c7f0524b6e..173db6cc77 100644
--- a/CodenameOne/src/com/codename1/maps/Coord.java
+++ b/CodenameOne/src/com/codename1/maps/Coord.java
@@ -19,6 +19,7 @@
*/
package com.codename1.maps;
+import com.codename1.location.LatLng;
import com.codename1.ui.geom.Dimension;
/**
@@ -26,7 +27,7 @@
*
* @author Roman Kamyk
*/
-public class Coord {
+public class Coord implements LatLng {
private double longitude;
private double latitude;