title: computeDistanceBetween Java vs Javascript
body: <p>So I am using google.maps.geometry.spherical.computeDistanceBetween in Javascript and computeDistanceBetween from SphericalUtil in Java.</p>
  
  <p><a href="https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/SphericalUtil.java" rel="nofollow noreferrer">https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/SphericalUtil.java</a></p>
  
  <p>I am getting different distances for the same positions. Is there anything I can do to calibrate them to be the same or are there two libraries I can use that can get me similar results in the front end (Javascript) and back end (Java)?</p>
  
  <p>Below are some values and an example:</p>
  
  <p>In Javascript:</p>
  
  <pre><code>var from = new google.maps.LatLng(33.44138, -111.97500000000002);
  var to = new google.maps.LatLng(33.505904166596224, -112.09470748901367);
  var distanceBetween = google.maps.geometry.spherical.computeDistanceBetween(from, to);
  console.log(distanceBetween);
  </code></pre>
  
  <p>In Java:</p>
  
  <pre><code>LatLng from = new LatLng(Float.parseFloat("33.44138"), Float.parseFloat("-111.97500000000002"));
  LatLng to = new LatLng(Float.parseFloat("33.505904166596224"), Float.parseFloat("-112.09470748901367"));
  double distanceBetween = SphericalUtil.computeDistanceBetween(from, to);
  System.out.println(distanceBetween);
  </code></pre>
  
  <p>In Java with Double instead of Float:</p>
  
  <pre><code>LatLng from = new LatLng(Double.parseDouble("33.44138"), Double.parseDouble("-111.97500000000002"));
  LatLng to = new LatLng(Double.parseDouble("33.505904166596224"), Double.parseDouble("-112.09470748901367"));
  double distanceBetween = SphericalUtil.computeDistanceBetween(from, to);
  System.out.println(distanceBetween);
  </code></pre>
  
  <p>The Javascript value is: 13234.355969270651
  The Java (float) value is: 13219.474110913057
  The Java (double) value is: 13219.565680296535</p>
  
  <p>Thanks!</p>