• chiran
  • NEWBIE
  • 5 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies

Here i want to display multiple markers on googlemap by passing data from the salesforce database instead of hard coding as if i have done before...So now i passed salesforce data in to an array in javascript .. Array having all Latitude values  related to a
particular city or address which i filter in my vpage picklist field ... FOr city==hyderabad i query all Latitude__c and Longitude__c  whose city =hyderabad..and passed this o/p to list and passed the list output to my array in javascript....SO array is as follows...


  var array3 = new Array();
 array3 = '{!leadrecords2}'.replace('[','').replace(']','').split(',');


for(i=0;i<array3.length;i++)
{
  var k=array3[i];
  alert(k);
    
}

here iam iterating through the loop to fetch all the values .... now i want to pass this values dynamically instead of hardcodingto the constructor new GLatLng( x, y ) Instead of x,y variables which i harrdcoded i want to pass all the values in my array3 as x argument and similarly i want to pass other array which has list of longitude values as y argument to that consructor so that the constructor fetches all the values in to array latlng[];



where leadrecords2 is as follows:

List<String> leadrecords2= new List<String>();
for(Integer i=0;i<leadrecords.size();i++)
          {
 leadrecords2.add(leadrecords[i].Latitude__c);
         }



and leadrecords is as follows


private List<Lead> leadrecords;
String query = 'SELECT  City,Latitude__c,Longitude__c FROM Lead WHERE City LIKE \''+city+'%\'';
        
        leadrecords = Database.query(query);


// this is the code for displaying multiple markers in the google map...


 
function showmarkers()
         {
         var x= '{!lat}';
         var y='{!longt}';
         var x1='{!lat1}';
          var y1='{!longt1}';
       var combi= '{!lat}' + ',' + '{!longt}';
        var combi1= '{!lat1}' + ',' + '{!longt1}';
  var map = new GMap2(document.getElementById("map_canvas"));
       
 // array were i wabnt to store all latitude and longitude values by passing my array s as arguments to constructor GLatLng




         var latlng1 =
         [
     new GLatLng( x, y ),
     new GLatLng(x1,y1)     
];
   map.setCenter( new GLatLng( 0, 0 ), 0 );
   
   for ( var i = 0; i < latlng1.length; i++ )
  {
    var marker = new GMarker( latlng1[ i ] );
    map.addOverlay( marker );
  }
var latlngbounds = new GLatLngBounds( );
  for ( var i = 0; i < latlng1.length; i++ )
  {
    latlngbounds.extend( latlng1[ i ] );
  }

  // #2b -- set center using the calculated values


  map.setCenter( latlngbounds.getCenter( ), map.getBoundsZoomLevel( latlngbounds ) );



          /*map.addoverlay will add markers to the maps overlay by calling new gmarker() passing the latitude and longitude as parameter... */


       
        
               marker.openInfoWindowHtml(combi);
            marker.openInfoWindowHtml(combi1);
       
        }

  • April 09, 2010
  • Like
  • 0

Hi everyone iam trying to define a javascript function which displays array values and inturn i pass a list of lead datatype to array..

where leadrecords is a list   
private List<Lead> leadrecords;
and  lead records is returned in this method...


 public PageReference view()
    {
        String query = 'SELECT  City,Latitude__c,Longitude__c FROM Lead WHERE City LIKE \''+city+'%\'';
        
        leadrecords = Database.query(query);
        
        /*for (Lead a : leadrecords ) */
        for(Integer i=1;i<leadrecords.size();i++)
          {
          
           += leadrecords[i].Latitude__c;
           longt=leadrecords[i].Longitude__c;
            if (i<leadrecords.size())
            {
              Integer j=i++;
              lat1=leadrecords[j].Latitude__c;                  
           
          }
          
         
         
       
    }
       return null;
   }


 Now i want to catch  the leadrecords field values (record values) and store it in a variable but not todisplay if i want to display i might have used pageblock table So  the following function trying to catch the values of leads by passing list to array and tring to catch values in for loop of array
function arraycheck()
{
  var array1=new Array();

array1='{!leadrecords}'.replace('[','').replace(']','').split(',');
for(j=0;j<array1.length;j++)
{
   document.write(array1[j] + "<br >");
    var x=array1[j];//giving id of the 1st record 00Q90000001Oj4KEAS//
    var y=array1[j++];//giving id of the 2nd record 00Q90000001Oj6kEAC//
    alert(x);
    alert(y);
}

But i want to catch the field value called Latitude__c from all the records of the list so how to loop the list and catch those values in the variable.....

Please correct me if iam wrong in my code and help me with an example code of doing what iam expecting

  • April 05, 2010
  • Like
  • 0

Hi iam trying to create apage with 2 field sets 1 will contain a form and the other will contain a googlemap....(inside the googlemap i have developed a search criteria when user click on go button i will pass the user entered address in to show address function and  then  i will raise an info window and pass the value to variable and den save it but here go button not working since iam pasisng html documents form value to the var and passing it to the functin show address ..So i dont know where iam going wrong .I want the go button to work so dat i can make search function(show address function work properly...)

 

                         Please help me out to solve d issue.. As iamnew in integarting googlemaps witth visualforce page...

 

                                                                                    Thanks and regards,


 

Visualforce Page:



<apex:page StandardController="Customer__c" Extensions="CustomerSignup" showHeader="false" sidebar="false">

<script>

function set1()
{
document.getElementById('fset1').style.display='block';
document.getElementById('fset2').style.display='none';
}

function set2()
{
document.getElementById('fset1').style.display='none';
document.getElementById('fset2').style.display='block';
}
</script>


<body onload="set1()" style="font-family:Arial, Times, serif;font-size:16px;margin:0 auto;padding:0;color:#525252;line-height:25px;">


<!--<apex:pageBlock title="Housing Maps">-->
<apex:form id="form1">
<apex:actionFunction name="callsubmit" action="{!save}" reRender="maintab"/>
<!--<fieldSet style="right:7%; left:7%;">-->
<!--<apex:pageBlockSection title="Provide Your Listings Here">-->

<apex:actionRegion >
<fieldset style="position:inherit;" id="fset1">
<table align ="center">

<tr><td align ="center"> <h1> &nbsp; &nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; SIGN UP </h1></td></tr>

<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>

<tr><td>
<apex:outputLabel value="Name:"></apex:outputLabel> </td>
<td><apex:inputText value="{!name}"/> </td></tr>




<tr><td>
<apex:outputLabel value="Email:"></apex:outputLabel> </td>
<td><apex:inputText value="{!email}"/> </td></tr>

<tr><td>
<apex:outputLabel value="Website:"></apex:outputLabel> </td>
<td> <apex:inputText value="{!web}"/> </td></tr>


<tr><td>
<apex:outputLabel value="Phone:"></apex:outputLabel> </td>
<td> <apex:inputText value="{!phone}"/> </td></tr>


<tr><td>
<apex:outputLabel value="Fax:"></apex:outputLabel> </td>
<td> <apex:inputText value="{!fax}"/> </td></tr>


<tr><td>
<apex:outputLabel value="Mobile:"></apex:outputLabel> </td>
<td> <apex:inputText value="{!mobile}"/> </td></tr>




<tr><td>
<apex:outputLabel value="Building Name:"></apex:outputLabel> </td>
<td> <apex:inputText value="{!building}"/> </td></tr>




<tr><td>
<apex:outputLabel value="Street Name:"></apex:outputLabel> </td>
<td> <apex:inputTextarea value="{!street}"/> </td></tr>




<tr><td>
<apex:outputLabel value="Landmark:"></apex:outputLabel> </td>
<td> <apex:inputText value="{!landmark}"/> </td></tr>


<tr><td>
<apex:outputLabel value="State:"></apex:outputLabel> </td>
<td> <apex:selectList value="{!states}" size="1">
<apex:selectOptions value="{!statesval}" rendered="true"></apex:selectOptions>
<apex:actionSupport event="onchange"/>
</apex:selectList></td></tr>


<tr><td>
<apex:outputLabel value="City:"></apex:outputLabel> </td>
<td> <apex:selectList value="{!city}" size="1">
<apex:selectOptions value="{!cityval}"></apex:selectOptions>
</apex:selectList></td></tr>





<tr><td>

<apex:outputLabel value="Area:"></apex:outputLabel> </td>

<td> <c:advancedLookup object="Bangalore__c" value="{!oppId}" maxHeight="20" width="250px" style="float: left"/>

<apex:actionStatus startText="elevator music...." id="status"/>
<apex:outputPanel id="detail">
<apex:detail subject="{!oppId}"/>
</apex:outputPanel></td>

<!--<td> <apex:inputText value="{!area}"/> </td>--></tr>



<tr><td>
<apex:outputLabel value="Pincode:"></apex:outputLabel> </td>
<td> <apex:inputText value="{!pincode}"/> </td></tr>


<tr><td>
<apex:outputLabel value="Rent:"></apex:outputLabel> </td>
<td> <apex:inputText value="{!rent}"/> </td></tr>


<tr><td>
<apex:outputLabel value="Advance:"></apex:outputLabel> </td>
<td> <apex:inputText value="{!advance}"/> </td></tr>


<tr><td>
<apex:outputLabel value="Facilities:"></apex:outputLabel> </td>
<td> <apex:inputTextarea value="{!facilities}"/> </td></tr>

<apex:commandButton reRender="fset1" value="Previous" onclick="set1()" />&nbsp;&nbsp;
<apex:commandButton rerender="fset2" value="Next" onclick="set2()" />
</table>
</fieldset>
</apex:actionRegion>


<!--<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>-->

<apex:actionRegion >
<fieldset style="position:inherit;" id="fset2"><table>
<script>
var myHtml2;

</script>
<!--
copyright (c) 2009 Google inc.

You are free to copy and use this sample.
License can be found here: http://code.google.com/apis/ajaxsearch/faq/#license
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps API Sample</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"></script>
<script type="text/javascript">

var map = null;
var geocoder = null;
var add=document.getElementById(t1.value);

function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.addControl(new GMapTypeControl());
map.addControl(new GSmallMapControl());

GEvent.addListener(map,"click", function(overlay,latlng) {
if (overlay) {
// ignore if we click on the info window
return;
}

var tileCoordinate = new GPoint();
var tilePoint = new GPoint();
var currentProjection = G_NORMAL_MAP.getProjection();
tilePoint = currentProjection.fromLatLngToPixel(latlng, map.getZoom());
tileCoordinate.x = Math.floor(tilePoint.x / 256);
tileCoordinate.y = Math.floor(tilePoint.y / 256);
/*var myHtml = "Latitude: " + latlng.lat() + "<br/>Longitude: " + latlng.lng() +
"<br/>The Tile Coordinate is:<br/> x: " + tileCoordinate.x +
"<br/> y: " + tileCoordinate.y + "<br/> at zoom level " + map.getZoom();
map.openInfoWindow(latlng, myHtml);
alert(myHtml);*/
myHtml2 = "Latitude: " + latlng.lat() ;
map.openInfoWindow(latlng, myHtml2);
alert(myHtml2);


});

geocoder = new GClientGeocoder();
}
}

function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}

</script>
</head>
<body onunload="GUnload()" style="font-family: Arial;border: 0 none;">
<input type="button" value="Show Map" Onclick="initialize()">
<form action="#" onsubmit="showAddress(add); return false">
<p>
<input type="text" id="t1" size="60" name="address" value="1600 Amphitheatre Pky, Mountain View, CA" />
<input type="submit" value="Go!" />

</p>
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</form>
</body>
</html>
<tr align="right"><td>
<apex:commandButton value="Submit" action="{!Save}"/>
<apex:commandButton reRender="fset1" value="Previous" onclick="set1()" />&nbsp;&nbsp;
<apex:commandButton rerender="fset2" value="Next" onclick="set2()" />
<apex:commandButton value="go2" onclick="showAddress(add)"/>
</td></tr>
</table>
</fieldset>
</apex:actionRegion>


<apex:inputHidden value="{!Customer__c.Latitude__c}" id="theField" />
<!– This is a method to get an element (or it’s Id) without hardcoding values –>

<script> var theField = document.getElementById('{!$Component.theField}'); </script>

<!– Grab the value of the Javascript variable and write it to the database –>
<apex:commandButton onclick="theField.value=myHtml2;" action="{!save}" value="save"/>



<!-- </fieldset>-->
<!--</apex:pageBlockSection>-->
</apex:form>
<!--</apex:pageBlock>-->

</body>
</apex:page>

 


 


 

                                                                                         

                                      

 

  • March 26, 2010
  • Like
  • 0

Hi everyone iam trying to define a javascript function which displays array values and inturn i pass a list of lead datatype to array..

where leadrecords is a list   
private List<Lead> leadrecords;
and  lead records is returned in this method...


 public PageReference view()
    {
        String query = 'SELECT  City,Latitude__c,Longitude__c FROM Lead WHERE City LIKE \''+city+'%\'';
        
        leadrecords = Database.query(query);
        
        /*for (Lead a : leadrecords ) */
        for(Integer i=1;i<leadrecords.size();i++)
          {
          
           += leadrecords[i].Latitude__c;
           longt=leadrecords[i].Longitude__c;
            if (i<leadrecords.size())
            {
              Integer j=i++;
              lat1=leadrecords[j].Latitude__c;                  
           
          }
          
         
         
       
    }
       return null;
   }


 Now i want to catch  the leadrecords field values (record values) and store it in a variable but not todisplay if i want to display i might have used pageblock table So  the following function trying to catch the values of leads by passing list to array and tring to catch values in for loop of array
function arraycheck()
{
  var array1=new Array();

array1='{!leadrecords}'.replace('[','').replace(']','').split(',');
for(j=0;j<array1.length;j++)
{
   document.write(array1[j] + "<br >");
    var x=array1[j];//giving id of the 1st record 00Q90000001Oj4KEAS//
    var y=array1[j++];//giving id of the 2nd record 00Q90000001Oj6kEAC//
    alert(x);
    alert(y);
}

But i want to catch the field value called Latitude__c from all the records of the list so how to loop the list and catch those values in the variable.....

Please correct me if iam wrong in my code and help me with an example code of doing what iam expecting

  • April 05, 2010
  • Like
  • 0
for(Integer i=1;i<leadrecords.size();i++)
          {
          
           lat= leadrecords[i].Latitude__c;
           longt=leadrecords[i].Longitude__c;
            if (i<leadrecords.size())
            {
              Integer j=i++;
              lat1=leadrecords[j].Latitude__c;
            }
           
           
          }

where leadrecords is the list and it is as follows...

 private List<Lead> leadrecords;
 
    public List<Lead> getLeadrecords()
    {
        return leadrecords;
    }

String query = 'SELECT  City,Latitude__c,Longitude__c FROM Lead WHERE City LIKE \''+city+'%\'';
        
        leadrecords = Database.query(query);

for(Integer i=1;i<leadrecords.size();i++)
          {
          
           lat= leadrecords[i].Latitude__c;
           longt=leadrecords[i].Longitude__c;
            if (i<leadrecords.size())
            {
              Integer j=i++;
              lat1=leadrecords[j].Latitude__c;
            }
           
           
          }

Now iam having two records in salesforce dbase whose city=bangalore..So i want to fetch each of these places corresponding  latitude value which is in my LIST LEADRECORDS BUT WHEN IAM DOING AS ABOVE iam always getting the latitude value of the ist records  but not the  2nd record of the loop please some one tell me how to iterate and pass the values to different strings so that i can catch those values in my javascript variables of my visualforce page..

Help me with an example so that i can clearly work out it..

                               Thanking You,