Back to project page Gamework.
The source code is released under:
Apache License
If you think the Android project Gamework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package cz.robyer.gamework.utils; //from w ww.j av a2s . com /** * Represents geographic coordinates. * @author Robert P?sel */ public class GPoint { public final double latitude; public final double longitude; /** * @param latitude * @param longitude */ public GPoint(double latitude, double longitude) { this.latitude = latitude; this.longitude = longitude; } /** * Slightly modified version of code from http://www.androidsnippets.com/distance-between-two-gps-coordinates-in-meter * @return Distance in meters between given coordinates */ public static double distanceBetween(double latFrom, double lonFrom, double latTo, double lonTo) { double pk = 180 / Math.PI; double a1 = latFrom / pk; double a2 = lonFrom / pk; double b1 = latTo / pk; double b2 = lonTo / pk; double t1 = Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math.cos(b2); double t2 = Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math.sin(b2); double t3 = Math.sin(a1) * Math.sin(b1); double tt = Math.acos(t1 + t2 + t3); double ellipsoidRadius = 6378.137 * (1 - 0.0033493 * Math.pow(Math.sin(0.5 * (latFrom + latTo)), 2)); return ellipsoidRadius * tt * 1000; } }