Version 4.3.6

This commit is contained in:
Neo committed 2025-12-19 05:49:12 -08:00
1 parent fe1acf984a
commit 1a0c7fd3c2
609 files changed
+14707 -5726

No files matched your search

+32 -3
View File
@@ -543,6 +543,11 @@ class _GeoLocation
return static::buildFromJson( $data );
}
/**
* @brief Cached lookups to prevent duplicate lookups
*/
static protected $lookupCache = array( 'latlong' => array(), 'address' => array() );
/**
* Get by latitude and longitude
*
@@ -554,18 +559,42 @@ class _GeoLocation
*/
public static function getByLatLong( $lat, $long )
{
return \IPS\GeoLocation\GeoCoder::i()->decodeLatLong( $lat, $long );
if( isset( static::$lookupCache['latlong'][ $lat . 'x' . $long ] ) )
{
return static::$lookupCache['latlong'][ $lat . 'x' . $long ];
}
static::$lookupCache['latlong'][ $lat . 'x' . $long ] = \IPS\GeoLocation\GeoCoder::i()->decodeLatLong( $lat, $long );
return static::$lookupCache['latlong'][ $lat . 'x' . $long ];
}
/**
* Get the latitude and longitude for the current object. Address must be set.
*
* @param bool $setAddress Whether or not to update the address information from the GeoCoder service
* @return void
* @throws \BadMethodCallException
*/
public function getLatLong()
public function getLatLong( $setAddress = FALSE )
{
\IPS\GeoLocation\GeoCoder::i()->setLatLong( $this );
$lookupKey = md5( $this->toString() );
if( isset( static::$lookupCache['address'][ $lookupKey ] ) )
{
foreach( json_decode( static::$lookupCache['address'][ $lookupKey ], true ) as $property => $value )
{
if( $property == 'lat' OR $property == 'long' OR $setAddress === TRUE )
{
$this->$property = $value;
}
}
return;
}
\IPS\GeoLocation\GeoCoder::i()->setLatLong( $this, $setAddress );
static::$lookupCache['address'][ $lookupKey ] = json_encode( $this );
}
/**