function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Robert RobinsonRobert Robinson 

Issues wih multiple location map

I am creating a map that pinpoints multiple locations (multiple locations in a MSA). The map involves two custom objects: Markets (MSA) and Properties. I have created the Visualforce Page and a related extension (both included below). The output should be split into two sections: the first (left) will be a list of the properties in the MSA, and the second block (right) will be the map itself. The VF Page and the extension compile without issue. When I run the page for an MSA value, the list appears on the left; however, the map does not appear. I must be missing something.

Visualforce Page
<apex:page sidebar="false" showHeader="false" standardController="Market__c" extensions="MSAProperty" >
  <!-- This page must be accessed with an Market Id in the URL. For example: 
       https://cs41.salesforce.com/apex/rrmultipropmap?id=a1255000002hr4G -->
  <apex:pageBlock >
    <apex:pageBlockSection Title="Properties in {!Market__c.Name} MSA"> 
      <apex:pageBlockTable value="{!mprops}" var="mp">
       <apex:column value="{!mp['Name']}"/>
       <apex:column value="{!mp['Address__c']}"/>
       <apex:column value="{!mp['City__c']}"/>
       <apex:column value="{!mp['State__c']}"/>
       <apex:column value="{!mp['Zip__c']}"/>
   <apex:map width="600px" height="400px" mapType="roadmap"
    center="{!mp.Address__c},{!mp.City__c},{!mp.State__c},{mp.Zip__c}">
     <apex:repeat value="{!mprops}" var="mp">
       <apex:mapMarker title="{! mp.Name }"
      position="{!mp.Address__c},{!mp.City__c},{!mp.State__c},{mp.Zip__c}"/>
     </apex:repeat>
   </apex:map>
     </apex:pageBlockTable>
    </apex:pageBlockSection>
  </apex:pageBlock>
</apex:page>

Apex Controller Extension
/*Controller class for the Multimktmap visualforce page used inline on Market layouts
to show only active Units related to the Property
*/
public class MSAProperty{
    public MSAProperty() {
    }
   public List<Property__c> mprops {get;set;}
   public MSAProperty(ApexPages.StandardController cont) {
      String ID = cont.getId();
      mprops = [Select Name, Address__c, City__c, State__c, Zip__c 
                  from Property__c 
                  where Market__c = :cont.getId()];
              }
        }
 
Best Answer chosen by Robert Robinson
Vincent Ip 7Vincent Ip 7
Right now your <apex:map> tag is sitting inside your <apex:pageBlockTable> and I believe that you didn't intend on putting a map on each table row.

So you need to pull out the map from the pageBlockTable, so I think you meant you have your page look like this.
 
<apex:page sidebar="false" showHeader="false" standardController="Market__c" extensions="MSAProperty" >
  <!-- This page must be accessed with an Market Id in the URL. For example: 
       https://cs41.salesforce.com/apex/rrmultipropmap?id=a1255000002hr4G -->
  <apex:pageBlock >
    <apex:pageBlockSection Title="Properties in {!Market__c.Name} MSA"> 
      <apex:pageBlockTable value="{!mprops}" var="mp">
        <apex:column value="{!mp['Name']}"/>
        <apex:column value="{!mp['Address__c']}"/>
        <apex:column value="{!mp['City__c']}"/>
        <apex:column value="{!mp['State__c']}"/>
        <apex:column value="{!mp['Zip__c']}"/>

      <!-- I've added this line -->
      </apex:pageBlockTable>


      <apex:map width="600px" height="400px" mapType="hybrid"
        center="{!Market__c.Address__c},{!Market__c.City__c},{!Market__c.State__c}">
        <apex:repeat value="{!mprops}" var="mp">
          <apex:mapMarker title="{! mp.Name }"
            position="{!mp.Address__c},{!mp.City__c},{!mp.State__c},{!mp.Zip__c}"/>
        </apex:repeat>
      </apex:map>

      <!-- I've commented this next line out
      </apex:pageBlockTable>
      -->

    </apex:pageBlockSection>
  </apex:pageBlock>
</apex:page>

 

All Answers

Vincent Ip 7Vincent Ip 7
there's a typo for {mp.Zip__c} on both apex:map and apex:mapMarker tags ( Missing the ! ).

Also not sure if you meant to have a repeat inside of your pageBlockTable.  Both are looping on the same list and using the same var alias "mp".
Robert RobinsonRobert Robinson
I have vastly simplified the VF page> Only one block, and I have added address fields to the Market object, so I can enter a record for the map center. The map still does not appear. The new Visualforce page:

<apex:page sidebar="false" showHeader="false" standardController="Market__c" extensions="MSAProperty" >
  <!-- This page must be accessed with an Market Id in the URL. For example: 
       https://cs41.salesforce.com/apex/rrmultipropmap?id=a1255000002hr4G -->
  <apex:pageBlock >
    <apex:pageBlockSection Title="Properties in {!Market__c.Name} MSA"> 
      <apex:pageBlockTable value="{!mprops}" var="mp">
       <apex:column value="{!mp['Name']}"/>
       <apex:column value="{!mp['Address__c']}"/>
       <apex:column value="{!mp['City__c']}"/>
       <apex:column value="{!mp['State__c']}"/>
       <apex:column value="{!mp['Zip__c']}"/>
   <apex:map width="600px" height="400px" mapType="hybrid"
    center="{!Market__c.Address__c},{!Market__c.City__c},{!Market__c.State__c}">
     <apex:repeat value="{!mprops}" var="mp">
       <apex:mapMarker title="{! mp.Name }"
      position="{!mp.Address__c},{!mp.City__c},{!mp.State__c},{!mp.Zip__c}"/>
     </apex:repeat>
   </apex:map>
     </apex:pageBlockTable>
    </apex:pageBlockSection>
  </apex:pageBlock>
</apex:page>

And the Apex Controller extension remains the same:
/*Controller class for the Multimktmap visualforce page used inline on Market layouts
to show only active Units related to the Property
*/
public class MSAProperty{
    public MSAProperty() {
    }
   public List<Property__c> mprops {get;set;}
   public MSAProperty(ApexPages.StandardController cont) {
      String ID = cont.getId();
      mprops = [Select Name, Address__c, City__c, State__c, Zip__c 
                  from Property__c 
                  where Market__c = :cont.getId()];
              }
        }
Vincent Ip 7Vincent Ip 7
Right now your <apex:map> tag is sitting inside your <apex:pageBlockTable> and I believe that you didn't intend on putting a map on each table row.

So you need to pull out the map from the pageBlockTable, so I think you meant you have your page look like this.
 
<apex:page sidebar="false" showHeader="false" standardController="Market__c" extensions="MSAProperty" >
  <!-- This page must be accessed with an Market Id in the URL. For example: 
       https://cs41.salesforce.com/apex/rrmultipropmap?id=a1255000002hr4G -->
  <apex:pageBlock >
    <apex:pageBlockSection Title="Properties in {!Market__c.Name} MSA"> 
      <apex:pageBlockTable value="{!mprops}" var="mp">
        <apex:column value="{!mp['Name']}"/>
        <apex:column value="{!mp['Address__c']}"/>
        <apex:column value="{!mp['City__c']}"/>
        <apex:column value="{!mp['State__c']}"/>
        <apex:column value="{!mp['Zip__c']}"/>

      <!-- I've added this line -->
      </apex:pageBlockTable>


      <apex:map width="600px" height="400px" mapType="hybrid"
        center="{!Market__c.Address__c},{!Market__c.City__c},{!Market__c.State__c}">
        <apex:repeat value="{!mprops}" var="mp">
          <apex:mapMarker title="{! mp.Name }"
            position="{!mp.Address__c},{!mp.City__c},{!mp.State__c},{!mp.Zip__c}"/>
        </apex:repeat>
      </apex:map>

      <!-- I've commented this next line out
      </apex:pageBlockTable>
      -->

    </apex:pageBlockSection>
  </apex:pageBlock>
</apex:page>

 
This was selected as the best answer
Robert RobinsonRobert Robinson
That simple. I KNEW there was something fundamental that I had bollixed up! Thank you, sir!!!!!
Now the last trick will be to assign different colors to each pin.