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?zoom=Zoom_Level&size=Map_WidthxMap_Height&markers=color:Marker_Color|label:Marker_Label|'+ TEXT(GeoLocation_Latitude_Field) + ',' + TEXT(GeoLocation_Longitute_Field), 'Title')

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

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

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s