Display Google Map in the formula field using geo-location fields

I came across a question on the answer community where someone is looking for a solution to display the google map on detail page using geolocation field. I thought it’s a good topic to write about so everyone will get benefitted.

Use case – I have a geolocation field on the Account object for storing the client’s office location, now I want to display that location on google map. Is that possible?

Solution – Yes, it’s pretty simple and anyone can do that using a formula field. Formula field will use the google map static API to display the image of the location. So, following are the steps to display the geolocation on google map.

  1. Create a formula field of Text type.
  2. Use IMAGE function in the formula which will render the image dynamically based on the passed geolocation.
    IMAGE('https://maps.googleapis.com/maps/api/staticmap?key=YOUR_API_KEY&zoom=Zoom_Level&size=Map_WidthxMap_Height&markers=color:Marker_Color|label:Marker_Label|'+ TEXT(GeoLocation_Latitude_Field) + ',' + TEXT(GeoLocation_Longitute_Field), 'Title')

You must also add your API Keys obtained from your google account.

New pricing changes went into effect on July 16, 2018 and that has made the Google API keys mandatory in the URL.

If you want to obtain the API keys then here is the link to the page – https://developers.google.com/maps/documentation/javascript/get-api-key

 

 

Why don’t we take a simple example? Yes, we should and that will help all of us to understand the solution.

Example – I have a field with label “Office location” (Geolocation field) and Office_Location__c is the API name. Now, it will have 2 integrated fields (Latitude__s and Longitude__s) for storing the latitude and longitude values respectively.

Now, I created a “Location on Map” formula field (Text) and following is the formula for that field.

IMAGE('https://maps.googleapis.com/maps/api/staticmap?zoom=13&size=300x200&markers=color:green|label:S|'+ TEXT(Office_Location__Latitude__s) + ',' + TEXT(Office_Location__Longitude__s), 'Office Location')

Here is the outcome from the above formula.

560d5f2ee4f8450e90e70367985b5851

Following URL can be useful to update the formula to leverage wonderful features of google map API.

Google Map Static API

 

About Naval Sharma

I am certified Salesforce Developer with Sales and Service cloud certifications. I am a true believer in #GivingBack principle and a Salesforce enthusiast. I am working as a member of our #SalesforceOhana to learn and help other fellow Trailblazers of the community to grow and learn. "I'm a true believer in karma. You get what you give, whether it's bad or good."

4 thoughts on “Display Google Map in the formula field using geo-location fields

  1. Amanda Almodova

    Hi Naval,

    Thanks for the post. That was exactly what I need it. However, even though I followed your instructions and the formula field seems correct. The image is not showing up on the details page and I can’t figure out why.. any ideas?

    Thank you

    Reply
      1. Amanda Almodova

        Thanks again Naval. but can you be more specific on what API keys I need, please? I tryed the Geolocation API key, the Maps Javascript APi and the Google Map Static API and I’m still not getting the image.
        Thank you

  2. Amanda Almodova

    Never mind! I figured out. My problem was an invalid size parameter.
    this is the formula I had to use:

    IMAGE(‘https://maps.googleapis.com/maps/api/staticmap?key=AIzaSyCMuglX6tFn5Bd_bk4snTUGcpbVXSIkiYY&zoom=Zoom_Level&size=252×142&markers=color:Marker_Color|label:Marker_Label|’+ TEXT( Geoloc_bin__Latitude__s ) + ‘,’ + TEXT( Geoloc_bin__Longitude__s ), ‘Bin Location’)

    Thanks anyway!

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.