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

+45 -1
View File
@@ -100,10 +100,11 @@ class _Google extends \IPS\GeoLocation\GeoCoder
* Get the latitude and longitude for the current object. Address must be set.
*
* @param \IPS\GeoLocation $geoLocation Geolocation object
* @param bool $setAddress Whether or not to update the address information from the GeoCoder service
* @return void
* @throws \BadMethodCallException
*/
public function setLatLong( \IPS\GeoLocation &$geoLocation )
public function setLatLong( \IPS\GeoLocation &$geoLocation, $setAddress = FALSE )
{
if ( \IPS\Settings::i()->googlemaps AND \IPS\Settings::i()->google_maps_api_key AND $geoLocation->toString() )
{
@@ -129,6 +130,49 @@ class _Google extends \IPS\GeoLocation\GeoCoder
$geoLocation->lat = $data['results'][0]['geometry']['location']['lat'];
$geoLocation->long = $data['results'][0]['geometry']['location']['lng'];
if( $setAddress === TRUE )
{
$_address = '';
/* Set the address data */
foreach( $data['results'][0]['address_components'] as $component )
{
if( $component['types'][0] == 'street_number' )
{
$_address = $component['long_name'];
}
elseif( $component['types'][0] == 'route' )
{
$_address .= " " . $component['long_name'];
}
if( $component['types'][0] == 'postal_code' )
{
$geoLocation->postalCode = $component['long_name'];
}
if( $component['types'][0] == 'country' )
{
$geoLocation->country = $component['short_name'];
}
if( $component['types'][0] == 'administrative_area_level_1' )
{
$geoLocation->region = $component['long_name'];
}
if( $component['types'][0] == 'locality' )
{
$geoLocation->city = $component['long_name'];
}
}
if( $_address )
{
$geoLocation->addressLines = array( $_address );
}
}
}
else
{
+45 -1
View File
@@ -99,10 +99,11 @@ class _Mapbox extends \IPS\GeoLocation\GeoCoder
* Get the latitude and longitude for the current object. Address must be set.
*
* @param \IPS\GeoLocation $geoLocation Geolocation object
* @param bool $setAddress Whether or not to update the address information from the GeoCoder service
* @return void
* @throws \BadMethodCallException
*/
public function setLatLong( \IPS\GeoLocation &$geoLocation )
public function setLatLong( \IPS\GeoLocation &$geoLocation, $setAddress = FALSE )
{
if ( \IPS\Settings::i()->mapbox AND \IPS\Settings::i()->mapbox_api_key AND $geoLocation->toString() )
{
@@ -126,6 +127,49 @@ class _Mapbox extends \IPS\GeoLocation\GeoCoder
$geoLocation->long = $data['features'][0]['center'][0];
$geoLocation->lat = $data['features'][0]['center'][1];
if( $setAddress === TRUE )
{
if( isset( $data['results'] ) AND is_array( $data['results'] ) AND count( $data['results'] ) )
{
foreach( $data['results'][0]['address_components'] as $component )
{
if( $component['types'][0] == 'street_number' )
{
$_address = $component['long_name'];
}
elseif( $component['types'][0] == 'route' )
{
$_address .= " " . $component['long_name'];
}
if( $component['types'][0] == 'postal_code' )
{
$geoLocation->postalCode = $component['long_name'];
}
if( $component['types'][0] == 'country' )
{
$geoLocation->country = $component['short_name'];
}
if( $component['types'][0] == 'administrative_area_level_1' )
{
$geoLocation->region = $component['long_name'];
}
if( $component['types'][0] == 'locality' )
{
$geoLocation->city = $component['long_name'];
}
}
}
if( $_address )
{
$geoLocation->addressLines = array( $_address );
}
}
}
else
{
+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 );
}
/**
+1 -1
View File
@@ -53,7 +53,7 @@ class _Mapbox
return "";
}
$location = $this->geolocation->long . ',' . $this->geolocation->lat;
$location = str_replace( ',', '.', $this->geolocation->long ) . ',' . str_replace( ',', '.', $this->geolocation->lat );
$imageUrl = \IPS\Http\Url::external( "https://api.mapbox.com/styles/v1/mapbox/streets-v10/static/pin-l-marker+f00({$location})/{$location},14,0,60/{$width}x{$height}@2x" )->setQueryString( array(
'access_token' => \IPS\Settings::i()->mapbox_api_key,