2

I am trying to write a query to find contacts within a radius of 50 miles and here is the SOQL i have

select Id,Name,mailingStreet,mailingState,mailingCity,mailingPostalCode,mailingcountry,Mailing_Address_Latitude__c,Mailing_Address_Longitude__c,Mailing_Address_Accuracy__c FROM Contact 
                        WHERE 

                        distance(MailingAddress, geolocation(30.2672, 97.7431), 'mi') < 50 
                        ORDER BY distance(MailingAddress, geolocation(30.2672, 97.7431), 'mi'),mailingCity
                        LIMIT 20];

For some reason i dont get any records even though there are no of contacts with mailing address nearby.

I also created a formula field just to see what what i am getting on the distance. Here is the formula

DISTANCE( GEOLOCATION( Mailing_Address_Latitude__c , Mailing_Address_Longitude__c ), GEOLOCATION( Random_office__Latitude__s , Random_office__Longitude__s ) , 'mi')

The coordinates given in SOQL/formula are of austin.

All the values in the field came out to be > 6000. I thought distance should in miles, but doesnt seem to be logically correct.

I verified 2 addresses in googlemap and its distance was around 7 miles.

Can anyone let know what units the distance method return in? Or what am i doing wrong here?

2

I think you are missing a - on the east/west coordinates?

30.2672, 97.7431 is somewhere in China

30.2672, -97.7431 is in Austin

  • 1
    Gosh!! time for coffee – Prady Oct 9 '18 at 14:50
1

The latitude and longitude are both in degrees. If altitude is included, it is measured in meters. Ref: Finding your position with Geolocation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.