i am trying to find nearest stores and their longitude and latitude based on customer location (lon,lat) and populate in Google map. Here is a sample query would work in MySQL. Would this same query work in Salesforce? Do we have **Radians function or equivalent function for Radians in salesforce**? Moreover, is this possible to frame a query like this?

```
SELECT
`id`,
`name`,
ACOS( SIN( RADIANS( `latitude` ) ) * SIN( RADIANS( $fLat ) ) + COS( RADIANS( `latitude` ) )
* COS( RADIANS( $fLat )) * COS( RADIANS( `longitude` ) - RADIANS( $fLon )) ) * 6380 AS `distance`
FROM `stations`
WHERE
ACOS( SIN( RADIANS( `latitude` ) ) * SIN( RADIANS( $fLat ) ) + COS( RADIANS( `latitude` ) )
* COS( RADIANS( $fLat )) * COS( RADIANS( `longitude` ) - RADIANS( $fLon )) ) * 6380 < 10
ORDER BY `distance`
```

Any ideas?

Thanks, Baskaran

Attribution to: Bforce

# Possible Suggestion/Solution #1

No, there is no radians function available directly in SOQL. However The new release of SOQL includes geolocation cababilities, you do not need to calculate distance yourself. Try something like:

ORDER BY Clause Sort records by distance using a distance condition in the ORDER BY clause. For example:

SELECT Name, StreetAddress_

c FROM Warehouse_c WHERE DISTANCE(Location_c, GEOLOCATION(37.775,-122.418), 'mi') < 20 ORDER BY DISTANCE(Location_c, GEOLOCATION(37.775,-122.418), 'mi') LIMIT 10

Attribution to: AlexandreJ

This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30347