Android Program to Calculate Distance between Two Latitude and Longitude Points

Here is source code of the Program to Calculate Distance between two points using Latitude & Longitude in Android. The program is successfully compiled and run on a Windows system using Eclipse Ide. The program output is also shown below.

Main Activity

package com.example.changeiamge;
import android.os.Bundle;
import android.renderscript.Type;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class MainActivity extends Activity implements OnCheckedChangeListener {
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        EditText lat_dest = (EditText) findViewById(;
        EditText lon_dest = (EditText) findViewById(;
        Button but1 = (Button) findViewById(;
        but1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // TODO Auto-generated method stub
                               Location mylocation = new Location("");
                                  Location dest_location = new Location("");
                               String lat = lat_dest.getText().toString();
                       String lon = lon_dest.getText().toString();
                               Double my_loc = 0.00;
                               Double distance = mylocation.distanceTo(dest_location);//in meters
                               Toast.makeText(this, "Distance"+Double.toString(distance),


Sanfoundry Global Education & Learning Series – 100+ Java Android Tutorials.

If you wish to look at all Tutorials, go to Java Android Tutorials.

If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.