title: How to find the distance between two places through road ?Should i use Json??How to extract the distance from map and show it on textview?
body: <p>I have found out two geolocation points and got the distance between two points.But it shows the shortest distance.I want to find the distance via road.How to use it??I dont have an idea about JSON??So with starting and ending points how to find the distacne through road??</p>
  
  <pre><code>    import java.util.List;
      import java.util.Locale;
  
      import android.app.Activity;
      import android.content.Context;
      import android.content.Intent;
      import android.location.Address;
      import android.location.Geocoder;
      import android.location.Location;
      import android.net.Uri;
      import android.os.Bundle;
      import android.util.FloatMath;
      import android.util.Log;
      import android.view.View;
      import android.view.View.OnClickListener;
      import android.widget.Button;
      import android.widget.EditText;
      import android.widget.TextView;
      import android.widget.Toast;
  
      public class WhereDoYouLive extends Activity {
          /** Called when the activity is first created. */
  
  
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);  // Set up GUI
  
      final EditText addressfield = (EditText) findViewById(R.id.address);  // Reference edit field
              final EditText addressfield2 = (EditText) findViewById(R.id.secaddress);
              final Button launchmapbtn = (Button) findViewById(R.id.launchmap);  // Reference search button
            final TextView lat=(TextView)findViewById(R.id.lat);
            final TextView lon=(TextView)findViewById(R.id.lon);
            final TextView lat2=(TextView)findViewById(R.id.lat2);
            final TextView lon2=(TextView)findViewById(R.id.lon2);
            final TextView result=(TextView)findViewById(R.id.res);
             final double latitude = 0 ;
            final double longitude = 0;
            final double latitude2 = 0;
            final double longitude2 = 0;
  
  
              launchmapbtn.setOnClickListener(new OnClickListener(){  
                      public void onClick(View v) { 
                          // List&lt;Address&gt; addresses=null;
                           String aa=addressfield.getText().toString();
                           String bb=addressfield2.getText().toString();
                           Geocoder geocoder = new Geocoder(getApplicationContext(),Locale.getDefault()); 
  
  
                          try {
  
  
      List&lt;Address&gt; addresses;
      addresses = geocoder.getFromLocationName(aa, 1);
  
      if(addresses.size() &gt; 0) {
          double latitude= addresses.get(0).getLatitude();
          double longitude= addresses.get(0).getLongitude();
         String lt=Double.toString(latitude);
          String lg=Double.toString(longitude);
          lat.setText(lt);
          lon.setText(lg);
      }
  
                          } catch (Exception e){
  
  
                          }   
  
  
  
                          try {
  
  
                              List&lt;Address&gt; addresses2 ;
                              addresses2 = geocoder.getFromLocationName(bb, 1);
  
                              if(addresses2.size() &gt; 0) {
                                  double latitude2= addresses2.get(0).getLatitude();
                                  double longitude2= addresses2.get(0).getLongitude();
                                  String lt2=Double.toString(latitude2);
                                  String lg2=Double.toString(longitude2);
                                  lat2.setText(lt2);
                                  lon2.setText(lg2);
  
                                  double finaldistance=distFrom ( latitude, longitude, latitude2, longitude2 );
                                  String finaldistance1=Double.toString(finaldistance)    ;
                                  result.setText(finaldistance1);
  
  
                              }
  
                              } catch (Exception e) {
                              // TODO: handle exception
                          }
  
  
  
                          }
              });
          }
  
  
         public static double distFrom(double lat1, double lng1, double lat2, double lng2) {
              double EARTH_RADIUS = 6371.00
  
  ; 
  
          double earthRadius = EARTH_RADIUS;
          double dLat = Math.toRadians(lat2-lat1);
          double dLng = Math.toRadians(lng2-lng1);
  
  
  
          double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
                  Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
                  Math.sin(dLng/2) * Math.sin(dLng/2);
          double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
          double dist = earthRadius * c;
  
          return new Float(dist).floatValue();
  
  
      }
  
  
  }
  </code></pre>
  
  <p>Here is the xml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      &gt;
  
      &lt;TextView 
          android:id="@+id/lat" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" /&gt;
  
        &lt;TextView 
          android:id="@+id/lon" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" /&gt;
  
        &lt;TextView 
          android:id="@+id/lat2" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" /&gt;
  
        &lt;TextView 
          android:id="@+id/lon2" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" /&gt;
        &lt;TextView 
          android:id="@+id/res" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" /&gt;
  
  
  &lt;EditText 
  android:text="Enter your address" 
  android:id="@+id/address" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content"&gt;
  &lt;/EditText&gt;
  
  &lt;EditText 
  android:text="Enter your secondaddress" 
  android:id="@+id/secaddress" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content"&gt;
  &lt;/EditText&gt;
  
  &lt;Button 
  android:text="Search" 
  android:id="@+id/launchmap" 
  android:layout_width="150px" 
  android:layout_height="wrap_content"&gt;
  &lt;/Button&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Here is the link to find the distance using google maps.just give the cordinates.
  <a href="https://maps.google.com/maps?saddr=79.7189,72.3414&amp;daddr=66.45,74.6333&amp;ie=UTF8&amp;om=0&amp;output=kml" rel="nofollow">Google map distance finder</a></p>
  
  <p>the cordinates i tried are 8.495,76.929167 and 8.5580957,76.8807437
  but the answer i got is around 8565.2763671.I dont know what its unit is (ie whether it is in kilometer or miles).But the correct answer should be 11.5kilometer or 11.7 kilometer.How can i get the correct answer???</p>