distance

Gives the distance between two points on the Earth given by their latitude and longitude, in kilometers unless a unit is given: "km", "mi" (miles) or "m" (meters).

Runs on: either side: the compiler places the statement that calls it where the values it uses live.

Format:

distance(lat1, lng1, lat2, lng2 [, unit])

Parameters:

Parameter Type Description
lat1 number the latitude of the first point, in degrees
lng1 number its longitude
lat2 number the latitude of the second point
lng2 number its longitude
unit string  [Optional]"km" (the default), "mi" or "m"

Returned Value:

Type Description
number the distance along the Earth's surface

Examples

miles = round(distance(here.lat, here.lng, store.lat, store.lng, "mi"), 1)