Last active
May 2, 2020 06:19
-
-
Save lukethacoder/9cf12d3ac6fabc6a27fd856a93f4074d to your computer and use it in GitHub Desktop.
Apex method to check distance between to lon/lat points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Account> listOfAccounts = [ SELECT Id, Name, ShippingLongitude, ShippingLatitude FROM Account WHERE ShippingLatitude != NULL]; | |
Location userLocation = Location.newInstance(-35.4330529, 149.0699176); | |
System.debug('a userLocation ' + userLocation); | |
for (Account account : listOfAccounts) { | |
Location placeLocation = Location.newInstance(account.ShippingLatitude, account.ShippingLongitude); | |
Double distanceBetween = Location.getDistance(userLocation, placeLocation, 'km'); | |
System.debug('Distance Between ' + distanceBetween + 'km'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment