2012-08-22 110 views
1

我试图在mapquest上找到2个位置之间的距离。我通过在JavaScript中对值进行了硬编码来实现这一点。现在我试图从2个帐户中获取值,并使用纬度和经度的值来查找距离。我已经创建了一个控制器,并在控制器中我有一个记录Longitude_ c和Latitude _c的列表,并且我已将值传递到JavaScript中,并在数组中添加。直到这个工作正常,但我的问题是,我只获得阵列的Id而不是Latitude_ c和Longitude _c字段的值。在列表中获取唯一标识

<apex:page id="pageId" standardController="Account"  extensions="checkDistanceController"> 
    <script src="http://www.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js?  key=Fmjtd%7Cluua250221%2C2a%3Do5-9620ua"></script> 

    <script type="text/javascript"> 


    function checkDistance(distance1) { 
     alert('{!listzise}'); 
     var listsizeJs = {!listzise}; 
     alert(listsizeJs); 
     var AcLon=new Array(); 
     var AcLat=new Array(); 
     var JsAcLst=new Array(); 

     var idx = 0; 
     <apex:repeat value="{!acLst}" var="ele"> 
      JsAcLst[idx++]="{!ele}"; 
     </apex:repeat> 



     for(var i=0; i<listsizeJs ; i++){ 
      alert("in for loop" + i); 
      var llone={lat:40.730318, lng:-73.990603}; 
      var llTow={lat:34.043897, lng:-118.209373}; 
      alert('Accunt List Apex : {!acLst}'); 
      alert('Accunt List JsLst:'+ JsAcLst[i]); 

     } 
      var distance = MQA.Util.arcDistance(llone, llTow, 'm'); 
      var distance1 = MQA.Util.distanceBetween(llone, llTow, 'm'); 
      alert(" Account Distance ........ " + Act_Distance); 

      document.getElementById("pageId:formId:theBlock:pageBlockSectionid1:outputId1").innerHTML=distance; 
      document.getElementById("pageId:formId:theBlock:pageBlockSectionid1:outputId2").innerH TML=distance1; 


}; 



    </script> 

    <apex:form id="formId"> 



      <apex:pageBlock title="Check Distance Between Vendors" mode="edit" id="theBlock" > 
        <apex:pageBlockButtons location="both"> 
          <apex:commandButton value="Find Distance" action="{!chkDistance}" onclick="checkDistance()" reRender="distanceID"/> 

        </apex:pageBlockButtons> 
        <apex:pageBlockSection columns="2" id="pageBlockSectionid1"> 

          <apex:outputText id="outputId1" label="Arc `Distance :"></apex:outputText> 
          <apex:outputText id="outputId2" label="Distance Between :"></apex:outputText> 

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

     </apex:form> 
</apex:page> 

控制器

public with sharing class checkDistanceController 
{ 

    public String Account { get; set; } 



    public Account theAccount{get;set;} 
    public Event_Equipment__c theEventEquipment{get;set;} 
    public string Longitude {get;set;} 
     public string Latitude {get;set;} 
     public list<Account> acLst {get; set;} 
    public decimal listzise{get;set;} 
     list<Account> acLst = new list<Account>(); 

    public checkDistanceController(ApexPages.StandardController controller) { 
     acLst = [Select Latitude__c, Longitude__c from Account where Longitude__c != null and Latitude__c != null limit 2]; 
     listzise = acLst.size(); 
    } 
    } 

任何人可以帮助我解决这个问题。

感谢 阿努

回答

0

你想放的经度和纬度的数组作为一个字符串?试试这个:

<apex:repeat value="{!acLst}" var="ele"> 
    JsAcLst[idx++]="{!ele.Latitude__c},{!ele.Longitude__c}"; 
</apex:repeat> 
+0

非常感谢。 – AnuRaj

+0

以及我应该怎么做多维数组。 – AnuRaj

+0

以下是有关多维数组的一些信息:http://www.kavoir.com/2009/02/javascript-multi-dimensional-array.html – mast0r