1

I've already activated "Clean Rules" Geocodes for Contact mailing Address in Salesforce. I understand from the links I've read that the geocodes don't actually show up unless through a custom field.

  1. How would I then create a custom field that shows the geolocations of my contacts' mailing address?

  2. My Sales people want to go on roadshows and have contacts that are close to one another show up if they show to be he Contact owner. How exactly do I achieve this? Can this be done on the UI through Geocodes?

I also saw another posting quoting below that has API code which I believe can achieve something in the lines of what I want. I'm not a developer and I don't fully grasp the coding nor would I know how to put this inside a Visualforce page. in my case, my object would be Contacts and the geocodes would be that of the mailing Address.

<apex:map width="600px" height="400px" mapType="roadmap"
center="{!Account.BillingStreet},{!Account.BillingCity},{!Account.BillingState}">

    <apex:repeat value="{! MyObj__c.Addresses }" var="addr">
      <apex:mapMarker title="{! addr.Name }"
        position="{!addr.MailingStreet},{!addr.MailingCity},{!addr.MailingState}"
      />
    </apex:repeat>

 </apex:map>
0

The Contact.MailingAddress composite field contains MailingLatitude and MailingLongitude as fields. Same pattern applies to Account.BillingAddress and Account.ShippingAddress as well.


Note from the documentation on the <apex:mapMarker> tag how the position attribute works:

Attribute Name
position

Attribute Type
Object

Description
Specifies the location of the marker. There are several ways to define the location:

  • A string representing an address. For example, "1 Market Street, San Francisco, CA". The address is automatically geocoded to determine its actual latitude and longitude.
  • A string representing a JSON object with latitude and longitude attributes that specify location coordinates. For example, "{latitude: 37.794, longitude: -122.395}".
  • 0 An Apex map object of type Map, with latitude and longitude keys to specify location coordinates.

Note: You can have up to 10 geocoded address lookups per map. Lookups for both the center attribute of the component and the position attribute of the component count against this limit. To display more markers, provide position values that don't require geocoding. Locations that exceed the geocoding limit are skipped.


Putting it all together, you should be able to use the following:

<apex:page standardController="Account">
    <apex:map height="800" width="800">
        <apex:mapMarker position="{latitude: {!Account.BillingLatitude}, longitude: {!Account.BillingLongitude}}" />
    </apex:map>
</apex:page>
  • I've put the above code in an an APex Class and when doing a quick save I get hte following error message: – Andrea Dec 5 '16 at 16:59
  • This is the error message I get when entering hte above code in the Apz controller: " Error: Compile Error: unexpected token: '<' at line 1 column 0" Also once that works, do I need to put this inside a visualforce page? How? can you guide me with the code? After I do this, will I be able to to view a google map with the surrounding Contacts that have geolocations nearby the contact that I'm currently on? How can I see this? – Andrea Dec 5 '16 at 17:00
  • This is the Visualforce markup...you don't even need Apex. – Adrian Larson Dec 5 '16 at 17:26
  • So I'm not quite clear then. What do I do? Do I cut and paste the above into a VisualForce page and then insert the page inside my Accounts or Contact screen? Will I then be able to see the locationso f my contacts nad accounts? I already have a Google map shoing hte location of the contactor Account which was already included out of hte box with Salesforce. What I'm wanting to do is make use of Geolocations that just came out in ord to be able to pull up all the Contact that are for example within 20 miles of hte current contact record. I'm not sure if this can be done and how? – Andrea Dec 6 '16 at 17:47
  • Your comments are a bit rambling and you added a new question in there (ask that separately), but yes, you would place the markup above into a Visualforce Page. You would then be able to include that page on any Page Layout for the Account object. – Adrian Larson Dec 6 '16 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.