Google Contacts in Google Apps Script

This Google Apps Script with fetch all the entries from your Google Contacts including the physical addresses. It then uses the geocoding service of Google Maps to turn these addresses into latitude and longtude points which are finally written to a KML file for reading inside Google Maps.

function Generate_KML() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ss.toast("Scanning your Google Contacts. Please wait..", "Scan Started", -1);

  var contacts = ContactsApp.getContacts();
  // Standard header of the KML File
  var kml  = '";
        kml += point.lng + "," + + "";
        kml += "";      
  kml += '';
  var attach = [{fileName:"address.kml", content:kml}];
  // Send the KML file as an email attachment to the current user
  GmailApp.sendEmail(Session.getEffectiveUser(), "Google Contacts Map", 
                     "Open the KML inside Google Earth", {attachments: attach});    

  // On-screen notification
  ss.toast("The KML file has been sent to your mailbox. Goodbye!", "Done", -1);