Skip to content

Commit cc9e784

Browse files
committed
Add optional radius parameter
1 parent fb35dfc commit cc9e784

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

geospatial.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ZEND_BEGIN_ARG_INFO(haversine_args,ZEND_SEND_BY_VAL)
3232
ZEND_ARG_INFO(0,fromLongitude)
3333
ZEND_ARG_INFO(0,toLatitude)
3434
ZEND_ARG_INFO(0,toLongitude)
35+
ZEND_ARG_INFO(0,radius)
3536
ZEND_END_ARG_INFO()
3637

3738
/* {{{ geospatial_functions[]
@@ -100,8 +101,8 @@ PHP_MINFO_FUNCTION(geospatial)
100101
PHP_FUNCTION(haversine)
101102
{
102103
double fromLat, fromLong, toLat, toLong, deltaLat, deltaLong;
103-
double latH, longH, result;
104-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dddd", &fromLat, &fromLong, &toLat, &toLong) == FAILURE) {
104+
double radius = GEO_EARTH_RADIUS, latH, longH, result;
105+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dddd|d", &fromLat, &fromLong, &toLat, &toLong, &radius) == FAILURE) {
105106
return;
106107
}
107108

@@ -114,7 +115,7 @@ PHP_FUNCTION(haversine)
114115
longH *= longH;
115116

116117
result = cos(fromLat * GEO_DEG_TO_RAD) * cos(toLat * GEO_DEG_TO_RAD);
117-
result = GEO_EARTH_RADIUS_IN_METERS * 2.0 * asin(sqrt(latH + result * longH));
118+
result = radius * 2.0 * asin(sqrt(latH + result * longH));
118119
RETURN_DOUBLE(result);
119120
}
120121

php_geospatial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern zend_module_entry geospatial_module_entry;
4141
* Calculate the radius using WGS-84's equatorial radius of
4242
* 6378137m
4343
*/
44-
#define GEO_EARTH_RADIUS_IN_METERS 6378.137
44+
#define GEO_EARTH_RADIUS 6378.137
4545

4646
PHP_MINIT_FUNCTION(geospatial);
4747
PHP_MINFO_FUNCTION(geospatial);

0 commit comments

Comments
 (0)