Geocodes are added only for some standard addresses:
- Billing Address on accounts
- Shipping Address on accounts
- Mailing Address on contacts
- Address on leads
Caution**
This feature needs to be enabled by the following steps:
- From Setup, enter Clean Rules in the Quick Find box, then select Clean Rules.
- Edit a geocode clean rule. There are four geocode clean rules available.
- Review your clean rule settings.
- Save the rule.
- Activate the rule.
- If Clean all records when this rule is activated or saved is selected, geocodes are automatically added to all existing records. New records automatically get geocodes when they’re saved. Existing geocode values are overwritten.
- Repeat this process for the other geocode clean rules.
Now you can create map with Visualforce!
A basic map without markers requires only an <apex:map> component. This component defines the map’s basic canvas, including its dimensions, location, and initial zoom level.
The center attribute defines the point around which the map is centered. You can provide center values in several formats.
- A string that represents an address. For example, "1 Market Street, San Francisco, CA". The address is geocoded to determine its latitude and longitude.
- A string that represents a JSON object with latitude and longitude attributes that specify location coordinates. For example, "{latitude: 37.794, longitude: -122.395}".
- An Apex map object of type Map<String, Double>, with latitude and longitude keys to specify location coordinates.
<apex:page standardController="Contact"> <!-- Display the address on a map --> <apex:map width="600px" height="400px" mapType="roadmap" zoomLevel="16" > <apex:mapMarker position="{!Contact.mailingLatitude}{!contact.mailingLongitude}" title="{!contact.Name}" > <apex:mapInfoWindow> <apex:outputPanel layout="block" style="font-weight: bold;"> <apex:outputText>{! contact.Name }</apex:outputText> </apex:outputPanel> <apex:outputPanel layout="block"> <apex:outputText> {!contact.MailingStreet},{!contact.MailingCity},{!contact.MailingState} </apex:outputText> </apex:outputPanel> </apex:mapInfoWindow> </apex:mapMarker> </apex:map> </apex:page>
This code produces the follow map.
- In this example, I have added the location marker by entering the Geocode from Contact.
- And even I didn't inpu the "Center" point in <Apex:map> , we can input display the location by adding the child <Apex:mapMaker> component.
- The mapType value is "roadmap", a standard street map. Other options are "satellite", and "hybrid".
- Using "<apex:map:inInfoWindow>" component, we can display more information regarding the location. The body of the <apex:mapInfoWindow> component is displayed in the info window when users click or tap the marker, and can be Visualforce markup, HTML and CSS, or plain text.
No comments:
Post a Comment