The docs on this are not new user friendly. For me the java docs worked best although theyre quite rigid: https://www.javadoc.io/doc/com.google.maps/google-maps-services/latest/com/google/maps/GeocodingApiRequest.html
Here is how to do so using the newest Google Geocoding API:
//use your google api key to create a GeoApiContext instance
GeoApiContext context = new GeoApiContext.Builder().apiKey("xxxxxx").build();
//this will get geolocation details via zip
GeocodingResult[]results = GeocodingApi.newRequest(context).components(ComponentFiler.postalCode("75002")).await();
System.out.println(results[0]);
//this will get geolocation details via address
GeocodingResult[] results2 = GeocodingApi.geocode(context, "One Apple Park Way Cupertino, CA 95014").await();
System.out.println(results2[0]);
//another way to get geolocation details via address
GeocodingResult[] results3 = GeocodingApi.newRequest(context).address("One Apple Park Way Cupertino, CA 95014").await();
System.out.println(results3[0]);
//geolocation details via lat lng
GeocodingResult[] results4 = GeocodingApi.newRequest(context).latlng(latLng).await();
System.out.println(results4[0]);
from there you'll get a bunch of data on the returned location in the results array, you can parse it as you wish to extract your choice of data. heres an ex of what that data looks like....
[GeocodingResult placeId=ChIJyTSQVXm0j4ARmdUQoA1BpwQ [Geometry: 37.31317000,-122.07238160 (APPROXIMATE) bounds=[37.34159500,-121.99557710, 37.24799500,-122.14382300], viewport=[37.34159500,-121.99557710, 37.24799500,-122.14382300]], formattedAddress=MONTE VISTA, CA 95014, USA, types=[postal_code], addressComponents=[[AddressComponent: "95014" ("95014") (postal_code)], [AddressComponent: "MONTE VISTA" ("MONTE VISTA") (locality, political)], [AddressComponent: "Santa Clara County" ("Santa Clara County") (administrative_area_level_2, political)], [AddressComponent: "California" ("CA") (administrative_area_level_1, political)], [AddressComponent: "United States" ("US") (country, political)]], postcodeLocalities=[Cupertino, MONTE VISTA, Permanente]]