I want to get the postcode of a UK address (e.g 9 Mallinson Road, London) inside Google Sheets (e.g B1). I am using the below code in C1 =mapAddress(B1) to get the full postal address from Google (39 Mallinson Road, London, SW11 3BW). It works well. However, I want a script that just gets the postcode for the address and a separate script that gets just the lat and long for a postcode. I can't use a splitting formula as the position of the postcode within a full address isn't always the same. Can you help?
function mapAddress(place, city, state) {
  var API_KEY = 'AIzaSyBE49ssuchansampleapihere';
  var url = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=' +
    place + ' ' + city + ' ' + state + '&key=' + API_KEY;
  var response = UrlFetchApp.fetch(url);
  var json = response.getContentText();
  obj = JSON.parse(json);
  addr = obj.results[0].formatted_address;
  return addr;
}
 
    