+ Start a Discussion
kskbgskskbgs 

Marking location point of all accounts in vf page using latitude and longitute of each account

Hi all
plz help me in creating a google map containing markers using lat/long fields of account.I was able to do by hard coding values but I want to generate dynamically.
see below code for ref.
<apex:page controller="TestExam">
<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["map"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
    
      var lat = [37.4232, 37.4289];
   
  var lon = [-122.0853, -122.1697];

  var data = new google.visualization.DataTable();
  data.addColumn('number', 'lat');
  data.addColumn('number', 'lon');

  for(i = 0; i < lat.length; i++)
    data.addRow([lat[i], lon[i]]);

     
        var map = new google.visualization.Map(document.getElementById('map_div'));
        map.draw(data, {showTip: true});
      }

    </script>
  </head>

  <body>
    <div id="map_div" style="width: 400px; height: 300px"></div>
  </body>
</html>
</apex:page>


I want to fetch lat,lon values from accounts dynamically

 
jp1234jp1234
Assuming that you have set BillingLatitude and BillingLongitude on all your accounts, you should be able to achieve that using Visualforce Remote objects (https://www.salesforce.com/us/developer/docs/pages/Content/pages_remote_objects.htm) to query for locations of all your accounts.  The Simple Visualforce Remote obejct example (https://www.salesforce.com/us/developer/docs/pages/index_Left.htm#CSHID=pages_remote_objects.htm|StartTopic=Content%2Fpages_remote_objects.htm|SkinName=webhelp) on Salesforce developer doc and your pre-exiting code should be enough to implement your code.