Payday Loan Payday Loan

Archive for April 15th, 2011

Hi, this is a function that calculates the distance betwen lat_a-lng_a and lat_b- lng_b coordinates.
I hope that will help you for easy programming your gps app.

package com.helloworld;
 
import android.app.Activity;
import android.os.Bundle;
import android.util.FloatMath;
import android.widget.TextView;
 
public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView text=(TextView)findViewById(R.id.textView1);
        double distance=gps2m(45.12,12.555,47.644,14.543);
        text.setText(String.valueOf(distance));
    }
 
    private double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) {
    	  float pk = (float) (180/3.14169);
 
    	  double a1 = lat_a / pk;
    	  double a2 = lng_a / pk;
    	  double b1 = lat_b / pk;
    	  double b2 = lng_b / pk;
 
    	  float t1 = FloatMath.cos((float) a1)*FloatMath.cos((float) a2)*
    	     FloatMath.cos((float) b1)*FloatMath.cos((float) b2);
    	  float t2 = FloatMath.cos((float) a1)*FloatMath.sin((float) a2)*
    	     FloatMath.cos((float) b1)*FloatMath.sin((float) b2);
    	  float t3 = FloatMath.sin((float) a1)*FloatMath.sin((float) b1);
    	  double tt = Math.acos(t1 + t2 + t3);
 
    	  return 6366000*tt;
    	}
}
||||| 0 I Like It! |||||

Search

Popular

Sponsors