I have a map, Map<Id, Contact> contactsMap in my apex class where key is the contact id and value is the contact itself. I am iterating over this map in visualforce page to get the contact's Location and mark it in the map(I have other functionality in the page with individual contact. Hence used a map. Using a list of contacts don't suffice my requirement). Below is the snippet of vf code:

    <apex:repeat value="{!contactsMap}" var="con">  
         <apex:map width="100%" height="320px" mapType="roadmap" zoomLevel="17" center="{!con.Address__c}" >        
              <apex:mapMarker id="mymap" position="{!con.Address__c}" rendered="true"/>     

The above piece of code isn't saving and the page throws the compile error as below:

Invalid type for attribute <apex:map id="mymap" center>: must be either String or Map.

Can someone let me know where I have went wrong and how this can be solved.

  • 1
    What is the type of Address__c field?
    – Lance Shi
    Apr 14, 2016 at 6:19
  • It is textarea field. @LanceShi
    – lalitha r
    Apr 14, 2016 at 6:36

4 Answers 4


An apex:repeat of a map iterates over the map keys so this is the required syntax:

<apex:repeat value="{!contactsMap}" var="key">  
    <apex:map width="100%" height="320px" mapType="roadmap" zoomLevel="17" center="{!contactsMap[key].Address__c}">        
        <apex:mapMarker id="mymap" position="{!contactsMap[key].Address__c}" rendered="true"/>     
  • Sorry thats my mistake. I have copied the question wrong but I have actually written it the way you mentioned. The error is coming with above code only. @keithc
    – lalitha r
    Apr 14, 2016 at 8:09
  • @lalithar OK then make sure the Address__c field is a string field of some type (e.g. text or picklist).
    – Keith C
    Apr 14, 2016 at 8:42
  • I made the field type to be text from textarea. I still have the issue. I don't think the issue is with field type, because if I query only one record and remove using apex:repeat, that is working fine and map is shown on the page.
    – lalitha r
    Apr 15, 2016 at 5:51
  • @lalithar If you do need to have the center attribute working, all I can suggest is for you to check that your data matches one of the documented formats.
    – Keith C
    Apr 15, 2016 at 7:03

Sahil Ravi: @Lalitha: try this it worked

<apex:page Controller="ContactMap">
<apex:form >
    <apex:pageBlock >
        <apex:repeat value="{!mapCont}" var="con">
            <apex:map width="100%" height="320px" mapType="roadmap" zoomLevel="17" center="{!mapCont[con].MailingCountry},{!mapCont[con].MailingStreet},{!mapCont[con].MailingCity},{!mapCont[con].MailingState}">        
               <apex:mapMarker id="mymap" position="{!mapCont[con].MailingCountry},{!mapCont[con].MailingStreet},{!mapCont[con].MailingCity},{!mapCont[con].MailingState}" rendered="true"/>


Try this <apex:repeat value="{!contactsMap.values()}" var="con">

  • Does map.values() work in page?
    – Ratan Paul
    Apr 14, 2016 at 7:02

Sahil @Lalitha: A string that represents an address. For example, "1 Market Street, San Francisco, CA". The address is geocoded to determine its latitude and longitude.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .