Get postcode from coordinates

@params string        $lon, $lat    the coordinates
@return object | null on Exception
7107
public function reverseGeocode($lon, $lat)
    {
        $url = '/postcodes?lon=' . (float) $lon . '&lat=' . (float) $lat;
        $request = new Request('GET', $url);

        return $this->httpTransport($request);
    }
1059330
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getName();
                break;
            case 2:
                return $this->getStreet();
                break;
            case 3:
                return $this->getZip();
                break;
            case 4:
                return $this->getCity();
                break;
            case 5:
                return $this->getCountryId();
                break;
            case 6:
                return $this->getPhone();
                break;
            case 7:
                return $this->getFax();
                break;
            case 8:
                return $this->getEmail();
                break;
            case 9:
                return $this->getLegalform();
                break;
            case 10:
                return $this->getLogo();
                break;
            case 11:
                return $this->getCreated();
                break;
            case 12:
                return $this->getNotes();
                break;
            default:
                return null;
                break;
        } // switch()
    }
1251556
def geocode(lat, lon, options = {})
      new(options.merge(lat: lat, lon: lon)).retrieve
    end
901764
def lonlat2xyz(lon, lat):
    """"""
    lat = xu.deg2rad(lat)
    lon = xu.deg2rad(lon)
    x = xu.cos(lat) * xu.cos(lon)
    y = xu.cos(lat) * xu.sin(lon)
    z = xu.sin(lat)
    return x, y, z
319560
public function getAddresses($postcode = null, $number = null, $from = 0)
    {
        return $this->get('/addresses/', [
            'postcode' => $postcode,
            'number' => $number,
            'from' => $from
        ]);
    }
354488
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getContactId();
                break;
            case 2:
                return $this->getContactType();
                break;
            case 3:
                return $this->getCreatedAt();
                break;
            case 4:
                return $this->getUpdatedAt();
                break;
            case 5:
                return $this->getVersion();
                break;
            case 6:
                return $this->getVersionCreatedAt();
                break;
            case 7:
                return $this->getVersionCreatedBy();
                break;
            case 8:
                return $this->getContactIdVersion();
                break;
            default:
                return null;
                break;
        } // switch()
    }
153601
public function getPostcodesByCoordinates($latitude, $longitude, $sort = self::POSTCODES_SORT_DISTANCE)
    {
        return $this->get('/postcodes/', [
            'coords' => [
                'latitude' => $latitude,
                'longitude' => $longitude
            ],
            'sort' => $sort
        ]);
    }
693060
public function geoCoder($lat, $lng, $ak, $mcode, $url)
    {
        $client = new \GuzzleHttp\Client();

        $parameters = [
            'form_params' => [
                'ak'       => $ak,
                'location' => $lat . ',' . $lng,
                'output'   => 'json',
                'pois'     => 0,
                'mcode'    => $mcode,
            ],
        ];

        $geo_coder = $client->request('POST', $url, $parameters);
        $geo_coder = json_decode($geo_coder->getBody());

        return $geo_coder;
    }
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);
		//*/
	}
1161572
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getVisible();
                break;
            case 2:
                return $this->getAddress1();
                break;
            case 3:
                return $this->getAddress2();
                break;
            case 4:
                return $this->getAddress3();
                break;
            case 5:
                return $this->getZipcode();
                break;
            case 6:
                return $this->getCity();
                break;
            case 7:
                return $this->getCountryId();
                break;
            case 8:
                return $this->getLatitude();
                break;
            case 9:
                return $this->getLongitude();
                break;
            case 10:
                return $this->getCreatedAt();
                break;
            case 11:
                return $this->getUpdatedAt();
                break;
            case 12:
                return $this->getVersion();
                break;
            case 13:
                return $this->getVersionCreatedAt();
                break;
            case 14:
                return $this->getVersionCreatedBy();
                break;
            default:
                return null;
                break;
        } // switch()
    }
752077
def get_lat_lon(self, exif_data):
        """"""
        lat = None
        lon = None

        if "GPSInfo" in exif_data:
            gps_info = exif_data["GPSInfo"]

            gps_latitude = self._get_if_exist(gps_info, "GPSLatitude")
            gps_latitude_ref = self._get_if_exist(gps_info, 'GPSLatitudeRef')
            gps_longitude = self._get_if_exist(gps_info, 'GPSLongitude')
            gps_longitude_ref = self._get_if_exist(gps_info, 'GPSLongitudeRef')

            if gps_latitude and gps_latitude_ref and gps_longitude and gps_longitude_ref:
                lat = self._convert_to_degress(gps_latitude)
                if gps_latitude_ref != "N":
                    lat = 0 - lat

                lon = self._convert_to_degress(gps_longitude)
                if gps_longitude_ref != "E":
                    lon = 0 - lon

        return lat, lon
570082
protected function loc($input){
    $input = urlencode($input);
    $urlindex =  '/authorities/subjects/suggest/?q=' . $input;
    $baseurl = 'https://id.loc.gov';
    $remoteUrl = $baseurl.$urlindex;
    $options['headers']=['Accept' => 'application/json'];
    $body = $this->getRemoteJsonData($remoteUrl, $options);

    $jsondata = [];
    $results = [];
    $jsondata = json_decode($body, TRUE);
    $json_error = json_last_error();
    if ($json_error == JSON_ERROR_NONE) {
      //LoC will always return at least one, the query string
      if (count($jsondata) > 1) {
        foreach ($jsondata[1] as $key => $label) {
          $results[] = [
            'value' => $jsondata[3][$key],
            'label' => $label
          ];
        }
      }
      else {
          $results[] = [
            'value' => NULL,
            'label' => 'Sorry no Match from LoC Subject Headings'
          ];
        }
      return  $results;
    }
    $this->messenger->addError(
      $this->t('Looks like data fetched from @url is not in JSON format.<br> JSON says: @$jsonerror <br>Please check your URL!',
        [
          '@url' => $remoteUrl,
          '@$jsonerror' => $json_error
        ]
      )
    );
    return [];
  }
1126277
def getTimeZone(lat, lon):
    
    #Need to fix for Python 2.x and 3.X support
    import urllib.request, urllib.error, urllib.parse
    import xml.etree.ElementTree as ET
    #http://api.askgeo.com/v1/918/aa8292ec06199d1207ccc15be3180213c984832707f0cbf3d3859db279b4b324/query.xml?points=37.78%2C-122.42%3B40.71%2C-74.01&databases=Point%2CTimeZone%2CAstronomy%2CNaturalEarthCountry%2CUsState2010%2CUsCounty2010%2CUsCountySubdivision2010%2CUsTract2010%2CUsBlockGroup2010%2CUsPlace2010%2CUsZcta2010
    req = "http://api.askgeo.com/v1/918/aa8292ec06199d1207ccc15be3180213c984832707f0cbf3d3859db279b4b324/query.xml?points="+str(lat)+"%2C"+str(lon)+"&databases=TimeZone"
    opener = urllib.request.build_opener()
    f = opener.open(req)
    tree = ET.parse(f)
    root = tree.getroot()
    #Check response
    tzid = None
    if root.attrib['code'] == '0':
        tz = list(root.iter('TimeZone'))[0]
        #shortname = tz.attrib['ShortName']
        tzid = tz.attrib['TimeZoneId']
    return tzid
1301414
public function encode($lat, $long)
        {
            //how many bits does latitude need?
            $plat = $this->precision($lat);
            $latbits = 1;
            $err = 45;

            while($err > $plat) {
                $latbits++;
                $err /= 2;
            }

            //how many bits does longitude need?
            $plong = $this->precision($long);
            $longbits = 1;
            $err = 90;

            while($err > $plong) {
                $longbits++;
                $err/=2;
            }

            //bit counts need to be equal
            $bits = max($latbits, $longbits);

            //as the hash create bits in groups of 5, lets not
            //waste any bits - lets bulk it up to a multiple of 5
            //and favour the longitude for any odd bits
            $longbits = $bits;
            $latbits  = $bits;
            $addlong  = 1;

            while (($longbits + $latbits) % 5 != 0) {
                $longbits += $addlong;
                $latbits += !$addlong;
                $addlong = !$addlong;
            }


            //encode each as binary string
            $blat = $this->binEncode($lat, -90, 90, $latbits);
            $blong = $this->binEncode($long, -180, 180, $longbits);

            //merge lat and long together
            $binary = "";
            $uselong = 1;

            while (strlen($blat) + strlen($blong)) {
                if ($uselong) {
                    $binary = $binary . substr($blong, 0, 1);
                    $blong = substr($blong, 1);
                } else {
                    $binary = $binary.substr($blat, 0, 1);
                    $blat = substr($blat, 1);
                }

                $uselong = !$uselong;
            }

            //convert binary string to hash
            $hash="";

            for ($i = 0; $i < strlen($binary); $i+=5) {
                $n = bindec(substr($binary, $i, 5));
                $hash = $hash . $this->coding[$n];
            }


            return $hash;
        }
95771
public static function latLngFromAddress ($address, $country = null)
	{
		/** @var Settings $settings */
		$settings = SimpleMap::getInstance()->getSettings();
		$token = static::getToken($settings->geoToken, $settings->geoService);

		switch ($settings->geoService)
		{
			case GeoEnum::Here:
				return static::_latLngFromAddress_Here(
					$token,
					$address, $country
				);
			case GeoEnum::GoogleMaps:
				return static::_latLngFromAddress_Google(
					$token,
					$address, $country
				);
			case GeoEnum::Mapbox:
				return static::_latLngFromAddress_Mapbox(
					$token,
					$address, $country
				);
			case GeoEnum::Nominatim:
				return static::_latLngFromAddress_Nominatim(
					$address, $country
				);
			default:
				throw new Exception(
					'Unknown geo-coding service: ' . $settings->geoService
				);
		}
	}
173362
def lonlat2xyz(lon, lat):
    

    lons = np.array(lon)
    lats = np.array(lat)

    xs = np.cos(lats) * np.cos(lons)
    ys = np.cos(lats) * np.sin(lons)
    zs = np.sin(lats)

    return xs, ys, zs
110328
public static void checkLatLong(double lat, double lon) {
		checkArgument(lon <= 181.0, "longitude out of range " + lon);
		checkArgument(lon > -180.0, "longitude out of range " + lon);
		checkArgument(lat <= 91.0, "latitude out of range " + lat);
		checkArgument(lat > -90.0, "latitude out of range " + lat);
	}