Access Address and Geolocation Compound Fields Using Apex

You can now access address and geolocation compound fields in Apex using the new Address and Location classes. You could previously access only compound fields’ component fields in Apex. You can now query compound fields and their components using the new Address and Location class methods.
Declare a variable of type Address or Location first, then access the subfields on that variable. For example, you can retrieve the city, zip code, and state values on an address field.
Account acct = [SELECT BillingAddress FROM account WHERE name='Acme' LIMIT 1];
Address addr = acct.BillingAddress;
String acctCity =;
String acctZipCode = addr.postalCode;
String acctState = addr.state;
Or, you can retrieve the latitude and longitude values of a geolocation field.
Account acct2 = [SELECT id, MyLocation__c FROM Account WHERE Name='Cloud Computing' LIMIT 1];
Location loc = acct2.MyLocation__c;
Double lat = loc.latitude;
Double lon = loc.longitude;