You need to sign in to do that
Don't have an account?
Errors occurring while working with GEOLOCATION and DISTANCE functions
I have 2 objects. DonLocation - it stores donor's username and its location (using geolocation)
ReqLocation - it stores hospital's username and its location. It stores location in 2 formats..one of them uses geolocation while other uses decimal fields to store latitude and longitude.
I am finding distance from certain hospital towards all donors. For that I am creating list of donors using SOQL query. Using for loop I am calculating distance for all donors.
But I facing many errors working with GEOLOCATION and DISTANCE function. Can anybody help me to solve this problem?
Here I am posting objects' structure and Code of controller class. Code Statement and error occuring for that statement is posted within comments.
Object 'DonLocation' structure Object API name - DonLocation__c
Field Label API Name Data Type
DonorPlace DonorPlace__c Geolocation
Username Username__c Text(20)
Object 'ReqLocation' structure Object API name - ReqLocation__c
Field Label API Name Data Type
HospLat HospLat__c Number(4, 14)
HospLocation HospLocation__c Geolocation
HospLong HospLong__c Number(4, 14)
Username Username__c Text(20)
Controller class "NearestDonors" Code with comments
public class NearestDonors{ public DonLocation__c dloc {get; set;} public ReqLocation__c hloc {get;set;} public double temp {get;set;} public double tempdouble {get;set;} public double tempnum {get;set;} public decimal tempdeci1 {get;set;} public decimal tempdeci2 {get;set;} // public location hgeo {get; set;} Error: Compile Error: Invalid type: location at line 9 column 11 public NearestDonors(){ map<string, double> distances = new map<string, double>(); hloc.HospLocation__Latitude__s=18.50134; hloc.HospLocation__Longitude__s=73.84113; List<DonLocation__c> dloclist = [select Username__c, DonorPlace__c from DonLocation__c]; if ((dloclist.size()) > 0) { for(DonLocation__c d : dloclist) { distances.put(d.Username__c,temp); /*tempnum = DISTANCE(GEOLOCATION(hloc.HospLat__c,hloc.HospLong__c),GEOLOCATION(d.DonorPlace__Latitude__s,d.DonorPlace__Longitude__s), 'km'); Error: Compile Error: Method does not exist or incorrect signature: GEOLOCATION(Decimal, Decimal) at line 23 column 26*/ /*tempdeci1=d.DonorPlace__Latitude__s; tempdeci2=d.DonorPlace__Longitude__s; tempnum = DISTANCE(GEOLOCATION(tempdeci1,tempdeci2),GEOLOCATION(hloc.HospLocation__Latitude__s,hloc.HospLocation__Longitude__s), 'km'); Error: Compile Error: Method does not exist or incorrect signature: GEOLOCATION(Decimal, Decimal) at line 30 column 24*/ /*tempnum = DISTANCE(GEOLOCATION(hloc.HospLocation__Latitude__s,hloc.HospLocation__Longitude__s),GEOLOCATION(d.DonorPlace__Latitude__s,d.DonorPlace__Longitude__s),'km'); Error: Compile Error: Method does not exist or incorrect signature: GEOLOCATION(Decimal, Decimal) at line 33 column 26 */ /*temp = DISTANCE(d.DonorPlace__c,GEOLOCATION(hloc.HospLocation__Latitude__s,hloc.HospLocation__Longitude__s), 'km'); Error: Compile Error: Data type not supported at line 36 column 23*/ /*temp=DISTANCE(d.DonorPlace__c, hloc.HospLocation__c, 'mi'); Error: Compile Error: Data type not supported at line 39 column 21 */ /*tempdouble = distance(DonorPlace__c,geolocation(hloc.HospLocation__Latitude__s,hloc.HospLocation__Longitude__s), 'km'); Error: Compile Error: Variable does not exist: DonorPlace__c at line 43 column 29*/ distances.put(d.Username__c,temp); } } } }
Can anybody help me to resolve this error? Thanks in advance..