Version 4.3.6
This commit is contained in:
1 parent
fe1acf984a
commit
1a0c7fd3c2
609 files changed
+14707
-5726
No files matched your search
@@ -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
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user