1

We are currently working on finding distance between two accounts using Google map integration. So, we are unable to find the solution for this. Can any one please help me out.

We are able to display the map and a particular account on the map using the account id in visualforce page.

2

You can use Google Maps to find distance between two accounts. Using Javascript remoting get toGeoLocation and fromGeoLocation in JS.

var from = new google.maps.LatLng(toGeoLocation.latitude__C, toGeoLocation.longitude__C);
var to   = new google.maps.LatLng(fromGeoLocation.latitude__C, fromGeoLocation.longitude__C);
var dist = google.maps.geometry.spherical.computeDistanceBetween(from, to);
| improve this answer | |
0

Please try this one using java script :

<script>
  var rad = function(x) {
     return x * Math.PI / 180;
  };

  var getDistance = function(p1, p2) {
  var R = 6378137; // Earth’s mean radius in meter
  var dLat = rad(p2.lat() - p1.lat());
  var dLong = rad(p2.lng() - p1.lng());
  var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
  Math.cos(rad(p1.lat())) * Math.cos(rad(p2.lat())) *
  Math.sin(dLong / 2) * Math.sin(dLong / 2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  var d = R * c;
  return d; // returns the distance in meter
};
</script>

also refer this link: https://stackoverflow.com/questions/1502590/calculate-distance-between-two-points-in-google-maps-v3

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.