Salesforce & Google Maps Integration

Himanshu Varshney
Senior Salesforce Developer
December 8, 2023

GoogleMapsSalesforce


Step 1: Set up Google Maps API Credentials

  1. Go to the Google Cloud Console.
  2. Create a new project or select an existing one.
  3. Enable the "Maps JavaScript API" for your project.
  4. Create API credentials (API Key).

Step 2: Create an Apex Class for Integration

// GoogleMapsIntegrationController.cls

public class GoogleMapsIntegrationController {
   public static String getGoogleMapsApiKey() {
       // Replace 'YOUR_GOOGLE_MAPS_API_KEY' with your actual API key
       return 'YOUR_GOOGLE_MAPS_API_KEY';
   }

   public static List<Account> getAccountsForMap() {
       // Query accounts or customize as per your use case
       return [SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingCountry, BillingPostalCode FROM Account LIMIT 10];
   }
}


Step 3: Create an Aura Component


<!-- GoogleMapsIntegration.cmp -->

<aura:component controller="GoogleMapsIntegrationController">
  <aura:attribute name="accounts" type="List" />

  <aura:handler name="init" value="{!this}" action="{!c.init}" />

  <div id="map"></div>

  <script>
      // Replace 'YOUR_GOOGLE_MAPS_API_KEY' with your actual API key
      const googleMapsApiKey = '{!GoogleMapsIntegrationController.getGoogleMapsApiKey()}';

      function initMap() {
          const map = new google.maps.Map(document.getElementById('map'), {
              center: { lat: -34.397, lng: 150.644 },
              zoom: 8
          });

          // Add markers for each account
          {!c.addMarkers}
      }
  </script>
</aura:component>


Step 4: Create the Aura Component Controller

// GoogleMapsIntegrationController.js

({
   init: function (component, event, helper) {
       // Fetch accounts from Salesforce
       var action = component.get("c.getAccountsForMap");
       action.setCallback(this, function (response) {
           var state = response.getState();
           if (state === "SUCCESS") {
               component.set("v.accounts", response.getReturnValue());
               helper.loadGoogleMapsScript();
           } else {
               console.error('Error fetching accounts');
           }
       });
       $A.enqueueAction(action);
   },

   addMarkers: function (component, event, helper) {
       var accounts = component.get("v.accounts");
       var map = new google.maps.Map(document.getElementById('map'));

       for (var i = 0; i < accounts.length; i++) {
           var account = accounts[i];
           var address = account.BillingStreet + ', ' + account.BillingCity + ', ' +
               account.BillingState + ', ' + account.BillingCountry + ' ' + account.BillingPostalCode;

           // Use the address to get latitude and longitude using Google Geocoding API
           // Add a marker for each account using the obtained coordinates
           {!c.addMarker}(map, address, account.Name);
       }
   },

   addMarker: function (map, address, title) {
       // Use the Google Geocoding API to get latitude and longitude
       // Create a marker and add it to the map
   }
});


Please note that the addMarker function needs to be implemented to make a callout to the Google Geocoding API to convert the address to latitude and longitude.

Additionally, you may need to handle asynchronous loading of the Google Maps API script. The loadGoogleMapsScript function in the helper should be responsible for dynamically loading the script. Ensure that you replace 'YOUR_GOOGLE_MAPS_API_KEY' with your actual API key.

Remember to handle errors, implement proper error handling, and adjust the code based on your specific requirements and best practices.

Share this article:
View all articles

Related Articles

Choosing the Right Data Sources for Training AI Chatbots featured image
December 12, 2025
If your AI chatbot sounds generic, gives wrong answers, or feels unreliable, the problem is probably not the model. It is the data behind it. In this article, you will see why choosing the right data sources matters more than any tool or framework. We walk through what data your chatbot should actually learn from, which sources help it sound accurate and confident, which ones quietly break performance, and how to use your existing knowledge without creating constant maintenance work. If you want a chatbot that truly reflects how your business works, this is where you need to start.
Lead Qualification Made Easy with AI Voice Assistants featured image
December 11, 2025
If your sales team is spending hours chasing leads that never convert, this is for you. Most businesses do not have a lead problem, they have a qualification problem. In this article, you will see how AI voice assistants handle the first conversation, ask the right questions, and surface only the leads worth your team’s time. You will learn how voice AI actually works, where it fits into real sales workflows, and why companies using it respond faster, close more deals, and stop wasting effort on unqualified prospects. If you want your leads filtered before they ever reach sales, keep reading.
The Automation Impact on Response Time and Conversions Is Bigger Than Most Businesses Realize featured image
December 9, 2025
This blog explains how response time has become one of the strongest predictors of conversions and why most businesses lose revenue not from poor marketing, but from slow follow up. It highlights how automation eliminates the delays that humans cannot avoid, ensuring immediate engagement across chat, voice, and form submissions. The post shows how automated systems capture intent at its peak, create consistent customer experiences, and significantly increase conversion rates by closing the gap between inquiry and response. Automation does not just improve speed. It transforms how the entire pipeline operates.

Unlock the Full Power of AI-Driven Transformation

Schedule a Demo

See how Anablock can automate and scale your business with AI.

Book Now

Start a Voice Call

Talk directly with our AI experts and get real-time guidance.

Call Now

Send us a Message

Summarize this page content with AI