title: Measure distance between two coordinates in an android app
body: <p>I'am trying to measure the distance between two coordinates, i've implemented the haversine function, just like this:</p>
  
  <pre><code>package Services;
  
  public class Route {
  
  private double latitude1;
  private double longitude1; 
  private double latitude2;
  private double longitude2; 
  
  
  public Route(double latitude1, double longitude1, double latitude2, double longitude2) {
  
      this.latitude1 = latitude1;
      this.longitude1 = longitude1;
      this.latitude2 = latitude2;
      this.longitude2 = longitude2;
  }
  
  public double measureDistance() {
  
       double earthRadius = 3958.75;
       double dLat = Math.toRadians(latitude2-latitude1);
       double dLng = Math.toRadians(longitude2-longitude1);
       double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
                     Math.cos(Math.toRadians(latitude1)) * Math.cos(Math.toRadians(latitude2)) *
                     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 dist; 
  }
  }
  </code></pre>
  
  <p>The code works fine and ouputting something. But as I use the haversine formula, the code just measure the distance in skyline, not the roads if you know what I mean. Is there any possible way to measure distance like google maps does? Without using the google maps API,  suddly google takes cash after 2500 API calls in a day or something..</p>