Stay organized with collections
Save and categorize content based on your preferences.
math.geo_distance
math.geo_distance(longitude1, latitude1, longitude2, latitude2))
Description
Returns the distance between two geographic locations (coordinates) in meters.
Returns -1 if the coordinates are invalid.
Parameter data types
FLOAT
, FLOAT
, FLOAT
, FLOAT
Return type
FLOAT
Code samples
Example 1
The following example returns the distance when all parameters are valid
coordinates:
math.geo_distance(-122.020287, 37.407574, -122.021810, 37.407574) = 134.564318
Example 2
The following example returns the distance when one of the parameters is a
truncated coordinate:
math.geo_distance(-122.000000, 37.407574, -122.021810, 37.407574) = 1926.421905
Example 3
The following example returns -1
when one of the parameters is an invalid
coordinate:
math.geo_distance(0-122.897680, 37.407574, 0-122.021810, 97.407574) = -1.000000
Example 4
The following example returns 0
when coordinates are the same:
math.geo_distance(-122.897680, 37.407574, -122.897680, 37.407574) = 0.000000
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-14 UTC."],[[["\u003cp\u003e\u003ccode\u003emath.geo_distance\u003c/code\u003e calculates the distance between two sets of geographic coordinates (longitude and latitude).\u003c/p\u003e\n"],["\u003cp\u003eThe function accepts four \u003ccode\u003eFLOAT\u003c/code\u003e type parameters representing the longitude and latitude of two locations and returns the distance as a \u003ccode\u003eFLOAT\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIf any of the provided coordinates are invalid, \u003ccode\u003emath.geo_distance\u003c/code\u003e returns -1.\u003c/p\u003e\n"],["\u003cp\u003eWhen both coordinates are the same, the function returns 0, indicating no distance between the coordinates.\u003c/p\u003e\n"],["\u003cp\u003eThe function is supported within the context of \u003ca href=\"/chronicle/docs/detection/default-rules\"\u003eRules\u003c/a\u003e.\u003c/p\u003e\n"]]],[],null,["### math.geo_distance\n\nSupported in: \n[Rules](/chronicle/docs/detection/default-rules) \n\n math.geo_distance(longitude1, latitude1, longitude2, latitude2))\n\n#### Description\n\nReturns the distance between two geographic locations (coordinates) in meters.\nReturns -1 if the coordinates are invalid.\n\n#### Parameter data types\n\n`FLOAT`, `FLOAT`, `FLOAT`, `FLOAT`\n\n#### Return type\n\n`FLOAT`\n\n#### Code samples\n\n##### Example 1\n\nThe following example returns the distance when all parameters are valid\ncoordinates: \n\n math.geo_distance(-122.020287, 37.407574, -122.021810, 37.407574) = 134.564318\n\n##### Example 2\n\nThe following example returns the distance when one of the parameters is a\ntruncated coordinate: \n\n math.geo_distance(-122.000000, 37.407574, -122.021810, 37.407574) = 1926.421905\n\n##### Example 3\n\nThe following example returns `-1` when one of the parameters is an invalid\ncoordinate: \n\n math.geo_distance(0-122.897680, 37.407574, 0-122.021810, 97.407574) = -1.000000\n\n##### Example 4\n\nThe following example returns `0` when coordinates are the same: \n\n math.geo_distance(-122.897680, 37.407574, -122.897680, 37.407574) = 0.000000"]]