Each of these methods is also equivalent to a read-only property. For each getter method you can access the property using dot notation. For example, myLocation.getLatitude() is equivalent to myLocation.latitude.
You can’t use dot notation to access compound fields’ subfields directly on the parent field. Instead, assign the parent field to a variable of type Location, and then access its components.
Location loc = myAccount.MyLocation__c;
Double lat = loc.latitude;
// Select and access the Location field. MyLocation__c is the name of a geolocation field on Account. Account[] records = [SELECT id, MyLocation__c FROM Account LIMIT 10]; for(Account acct : records) { Location loc = acct.MyLocation__c; Double lat = loc.latitude; Double lon = loc.longitude; } // Instantiate new Location objects and compute the distance between them in different ways. Location loc1 = Location.newInstance(28.635308,77.22496); Location loc2 = Location.newInstance(37.7749295,-122.4194155); Double dist = Location.getDistance(loc1, loc2, 'mi'); Double dist2 = loc1.getDistance(loc2, 'mi');
The following are methods for Location.
public Double getDistance(Location toLocation, String unit)
Type: Double
public static Double getDistance(Location firstLocation, Location secondLocation, String unit)
Type: Double