Find an address from the given lat/lng

@param float $lat
@param float $lng

@return array|null - Returns the address and associated parts
@throws Exception
195973
public static function addressFromLatLng ($lat, $lng)
	{
		/** @var Settings $settings */
		$settings = SimpleMap::getInstance()->getSettings();
		$token    =
			static::getToken($settings->geoToken, $settings->geoService);

		switch ($settings->geoService)
		{
			case GeoEnum::Here:
				return static::_addressFromLatLng_Here(
					$token,
					$lat, $lng
				);
			case GeoEnum::GoogleMaps:
				return static::_addressFromLatLng_Google(
					$token,
					$lat, $lng
				);
			case GeoEnum::Mapbox:
				return static::_addressFromLatLng_Mapbox(
					$token,
					$lat, $lng
				);
			case GeoEnum::Nominatim:
				return static::_addressFromLatLng_Nominatim(
					$lat, $lng
				);
			default:
				throw new Exception(
					'Unknown geo-coding service: ' . $settings->geoService
				);
		}
	}
707185
public function latLng()
    {
        $lat = $this->lat();
        $lng = $this->lng();

        if ($lat && $lng) {
            return [ $lat, $lng ];
        } else {
            return null;
        }
    }
620652
def address(lat, lng, *, raw=False):
    
    try:
        lat, lng = wgs_to_gk4(lat, lng)
        r = requests.get(
            url='https://www.dvb.de/apps/map/address',
            params={
                'lat': lat,
                'lng': lng,
            },
        )
        if r.status_code == 200:
            response = json.loads(r.content.decode('utf-8'))
        else:
            raise requests.HTTPError('HTTP Status: {}'.format(r.status_code))
    except requests.RequestException as e:
        print('Failed to access DVB map address app. Request Exception', e)
        response = None

    if response is None:
        return None
    return response if raw else process_address(response)
631889
function isSea(lat, lng) {
  if (landLookup === null) {
    const map = getMap();
    landLookup = new GeoJsonLookup(map);
  }

  return landLookup.hasContainers({type: 'Point', coordinates: [lng, lat]});
}
272728
public static function pointDMS(array $bounds = null)
    {
        list($lat, $lng) = static::point($bounds);

        return sprintf('%s %s', self::floatToDMS($lat), self::floatToDMS($lng));
    }
638592
protected function lookupGeo($address, $country)
    {
        // Trim the data. Better!
        $address = \trim($address);
        $country = \trim($country);

        // First check cache.
        $cacheResult = $this->getFromCache($address, $country);
        if (null !== $cacheResult) {
            return $cacheResult;
        }

        // If there is no data from the cache ask google.
        $lookupServices = (array) StringUtil::deserialize($this->get('lookupservice'), true);
        if (!\count($lookupServices)) {
            return null;
        }

        foreach ($lookupServices as $lookupService) {
            try {
                $callback = $this->getObjectFromName($lookupService['lookupservice']);

                // Call the main function.
                if (null !== $callback) {
                    /** @var Container $result */
                    $result = $callback
                        ->getCoordinates(
                            null,
                            null,
                            null,
                            $country,
                            $address,
                            $lookupService['apiToken'] ?: null
                        );

                    // Check if we have a result.
                    if (!$result->hasError()) {
                        $this->addToCache($address, $country, $result);

                        return $result;
                    }
                }
            } catch (\RuntimeException $exc) {
                // Okay, we have an error try next one.
                continue;
            }
        }

        // When we reach this point, we have no result, so return false.
        return null;
    }
1132675
public function getCoordinates(
        ?string $street = null,
        ?string $streetNumber = null,
        ?string $city = null,
        ?string $zip = null,
        ?string $country = null
    ): Coordinates {
        $items = [];
        $variables = [$street, $streetNumber, $city, $zip, $country];
        foreach ($variables as $variable) {
            if (empty($variable)) {
                continue;
            }

            $items[] = $variable;
        }

        $results = $this->doCall(array(
            'address' => implode(' ', $items),
            'sensor' => 'false'
        ));

        if (!array_key_exists(0, $results)) {
            throw Exception::noCoordinatesFoundforAddress($variables);
        }

        return new Coordinates(
            $results[0]->geometry->location->lat,
            $results[0]->geometry->location->lng
        );
    }
520908
public function location($entity, $config = array())
    {
        if(!$entity->isGeolocatable()) {
           throw new Exception('Entity is not geolocatable');
        }

        $config['entity'] = $entity;
        $config['locations'] = $entity->locations;

        return $this->_render('location', $config);
    }
1161056
public static function latToPixels($lat, $zoom)
    {
        if ($lat == 90) {
            $pixelY = 0;
        } elseif ($lat == -90) {
            $pixelY = 256;
        } else {
            $latRad = deg2rad($lat);
            $mercY = log(tan(pi() / 4 + $latRad / 2));
            $cartY = pi() - $mercY;
            $pixelY = $cartY * 256 / 2 / pi();
            $pixelY = max(0, $pixelY); // correct rounding errors near north and south poles
            $pixelY = min(256, $pixelY); // correct rounding errors near north and south poles
        }
        $pixelYZoom = $pixelY * pow(2, $zoom);

        return $pixelYZoom;
    }
848179
public function geocode($address)
    {
        $gecode = $this->_url.'address='.urlencode($address);

        if($this->_key){
            $gecode .= '&key='.$this->_key;
        }

        $data = json_decode(file_get_contents($gecode),true);

        $this->_status = $data['status'];

        if ($this->_status === 'OK') {
            $results = $data['results'][0]['geometry']['location'];
            $location = array(
                'longitude' => $results['lng'],
                'latitude' => $results['lat'],
                'results' => $data['results'],
            );

            return $location;
        } else {
            return false;
        }
    }
92960
private static function  mercatorLatRhumb( $lat1, $lat2,  $lng2,  $lng3) {
        
        return (MathUtil::mercator($lat1) * ($lng2 - $lng3) + MathUtil::mercator($lat2) * $lng3) / $lng2;
    }
609589
public function mercator_decrypt($mercatorLat, $mercatorLon)
	{
		$x = $mercatorLon / 20037508.34 * 180.;
		$y = $mercatorLat / 20037508.34 * 180.;
		$y = 180 / $this->PI * (2 * atan(exp($y * $this->PI / 180.)) - $this->PI / 2);
		return array('lat' => $y, 'lon' => $x);
		/*
		if (abs($mercatorLon) < 180 && abs($mercatorLat) < 90)
			return NULL;
		if ((abs($mercatorLon) > 20037508.3427892) || (abs($mercatorLat) > 20037508.3427892))
			return NULL;
		$a = $mercatorLon / 6378137.0 * 57.295779513082323;
		$x = $a - (floor((($a + 180.0) / 360.0)) * 360.0);
		$y = (1.5707963267948966 - (2.0 * atan(exp((-1.0 * $mercatorLat) / 6378137.0)))) * 57.295779513082323;
		return array('lat' => $y, 'lon' => $x);
		//*/
	}
903497
public function getDistance($lat, $lng, $scale = 'km'){
		return GeoFunctions::getDistance($this->getLatitude(), $this->getLongditude(), $lat, $long, $scale);
	}
754089
function geoGetCoords($address,$depth=0) {
	    $_coords = false;
        switch($this->lookup_service) {
            case 'GOOGLE':
                $_url = sprintf('http://%s/maps/api/geocode/json?sensor=%s&address=%s',$this->lookup_server['GOOGLE'], $this->mobile==true?"true":"false", rawurlencode($address));
                if($_result = $this->fetchURL($_url)) {
                    $_result_parts = json_decode($_result);
                    if($_result_parts->status!="OK"){
                    	return false;
                    }
                    $_coords['lat'] = $_result_parts->results[0]->geometry->location->lat;
                    $_coords['lon'] = $_result_parts->results[0]->geometry->location->lng;
                }
                break;
            case 'YAHOO':
            default:        
                $_url = sprintf('http://%s/MapsService/V1/geocode?appid=%s&location=%s',$this->lookup_server['YAHOO'],$this->app_id,rawurlencode($address));
                if($_result = $this->fetchURL($_url)) {
                    preg_match('!<Latitude>(.*)</Latitude><Longitude>(.*)</Longitude>!U', $_result, $_match);
                    $_coords['lon'] = $_match[2];
                    $_coords['lat'] = $_match[1];
                }
                break;
        }         
        return $_coords;       
    }
1238651
public String getCountryByLatLon(double lat, double lon){
		double[] q = new double[2];
		q[0] = lat;
		q[1] = lon;
		LightweightGeoObject city = null;
		try {
			city = (LightweightGeoObject)tree.nearest(q);
		} catch (KeySizeException e) {
			logger.error(e.getMessage());
		}
		if (city == null) return null;
		return countryCodes.get(city.getCountryCode());
	}
57265
public function getForecast($lat, $long)
    {
        $endpoint = sprintf('/forecast/%s/%s,%s', $this->apiKey, $lat, $long);
        return $this->makeAPIRequest($endpoint);
    }
832794
public function getAddress(float $latitude, float $longitude): Address
    {
        $addressSuggestions = $this->getAddresses($latitude, $longitude);

        if (count($addressSuggestions) == 0) {
            throw Exception::noAddressFoundForCoordinates($latitude, $longitude);
        }

        return $addressSuggestions[0];
    }