Convert a latitude and longitude to an UTM reference

@return the converted UTM reference
516351
public function toUTMRef()
	{
		$wgs84 = new ReferenceEllipsoid(ReferenceEllipsoid::WGS84_MAJ, ReferenceEllipsoid::WGS84_MIN);

		$UTM_F0	 = 0.9996;
		$a = $wgs84->maj;
		$eSquared = $wgs84->ecc;
		$longitude = $this->lng;
		$latitude = $this->lat;

		$latitudeRad = $latitude * (pi() / 180.0);
		$longitudeRad = $longitude * (pi() / 180.0);
		$longitudeZone = (int) (($longitude + 180.0) / 6.0) + 1;

		// Special zone for Norway
		if ($latitude >= 56.0
			&& $latitude < 64.0
			&& $longitude >= 3.0
			&& $longitude < 12.0
		) {
			$longitudeZone = 32;

			// Special zones for Svalbard
			if ($latitude >= 72.0 && $latitude < 84.0) {
				if ($longitude >= 0.0 && $longitude < 9.0) {
					$longitudeZone = 31;
				} else if ($longitude >= 9.0 && $longitude < 21.0) {
					$longitudeZone = 33;
				} else if ($longitude >= 21.0 && $longitude < 33.0) {
					$longitudeZone = 35;
				} else if ($longitude >= 33.0 && $longitude < 42.0) {
					$longitudeZone = 37;
				}
			}
		}

		$longitudeOrigin = ($longitudeZone - 1) * 6 - 180 + 3;
		$longitudeOriginRad = $longitudeOrigin * (pi() / 180.0);

		$UTMZone = getUTMLatitudeZoneLetter($latitude);

		$ePrimeSquared = ($eSquared) / (1 - $eSquared);

		$n = $a / sqrt(1 - $eSquared * sin($latitudeRad) * sin($latitudeRad));
		$t = tan($latitudeRad) * tan($latitudeRad);
		$c = $ePrimeSquared * cos($latitudeRad) * cos($latitudeRad);
		$A = cos($latitudeRad) * ($longitudeRad - $longitudeOriginRad);

		$M = $a
			* ((1
			- $eSquared / 4
			- 3 * $eSquared * $eSquared / 64
			- 5 * $eSquared * $eSquared * $eSquared / 256)
			* $latitudeRad
			- (3 * $eSquared / 8
				+ 3 * $eSquared * $eSquared / 32
				+ 45 * $eSquared * $eSquared * $eSquared / 1024)
				* sin(2 * $latitudeRad)
			+ (15 * $eSquared * $eSquared / 256
				+ 45 * $eSquared * $eSquared * $eSquared / 1024)
				* sin(4 * $latitudeRad)
			- (35 * $eSquared * $eSquared * $eSquared / 3072)
				* sin(6 * $latitudeRad));

		$UTMEasting = (double) ($UTM_F0
			* $n
			* ($A
			+ (1 - $t + $c) * pow($A, 3.0) / 6
			+ (5 - 18 * $t + $t * $t + 72 * $c - 58 * $ePrimeSquared)
				* pow($A, 5.0)
				/ 120)
			+ 500000.0);

		$UTMNorthing = (double) ($UTM_F0
			* ($M
			+ $n
				* tan($latitudeRad)
				* ($A * $A / 2
				+ (5 - $t + (9 * $c) + (4 * $c * $c)) * pow($A, 4.0) / 24
				+ (61 - (58 * $t) + ($t * $t) + (600 * $c) - (330 * $ePrimeSquared))
					* pow($A, 6.0)
					/ 720)));

		// Adjust for the southern hemisphere
		if ($latitude < 0) {
			$UTMNorthing += 10000000.0;
		}

		return new UTMRef($UTMEasting, $UTMNorthing, $UTMZone, $longitudeZone);
	}
392713
def latitude(self):
        ''''''
        sd = dm_to_sd(self.lat)
        if self.lat_dir == 'N':
            return +sd
        elif self.lat_dir == 'S':
            return -sd
        else:
            return 0.
934953
public double getY01FromLatitude(double latitude, boolean wrapEnabled) {
		latitude = wrapEnabled ? Clip(latitude, getMinLatitude(), getMaxLatitude()) : latitude;
		final double result = getY01FromLatitude(latitude);
		return wrapEnabled ? Clip(result, 0, 1) : result;
	}
385922
public List<LatLng> getLatLngs() {
    List<LatLng>latLngs = new ArrayList<>();
    if (geometry!=null) {
      for (Point coordinate : geometry.coordinates()) {
        latLngs.add(new LatLng(coordinate.latitude(), coordinate.longitude()));
      }
    }
    return latLngs;
  }
579149
public GeocodingResult toGeocodingResult(
            final GeoServiceGeocodingResult gsResult) {
        if (gsResult == null) {
            return null;
        }
        final GeocodingResult result = new GeocodingResult();
        final AddressComponent[] addressComponents =
                gsResult.getAddressComponents();
        if (addressComponents == null) {
            result.addressComponents = null;
        } else {
            result.addressComponents =
                    new AddressComponent[addressComponents.length];
            for (int i = 0; i < addressComponents.length; i++) {
                result.addressComponents[i] = copy(addressComponents[i]);
            }
        }
        result.formattedAddress = gsResult.getFormattedAddress();
        result.geometry = toGeometry(gsResult.getGeometry());
        result.partialMatch = gsResult.isPartialMatch();
        result.placeId = gsResult.getPlaceId();
        // This is safe because the gs object returns a copy of its array.
        result.postcodeLocalities = gsResult.getPostcodeLocalities();
        // This is safe because the gs object returns a copy of its array.
        result.types = gsResult.getTypes();
        return result;
    }
559396
public GeocodeApiResponse.Location getLocation() {
        final GeocodeApiResponse.Result firstResult = firstResult(apiResponse);
        if(firstResult == null) {
            return null;
        }
        final GeocodeApiResponse.Geometry geometry = firstResult.getGeometry();
        if (geometry == null) {
            return null;
        }
        return geometry.getLocation();
    }
351810
private static double latitudeToY(double latitude) {
        double sinLatitude = Math.sin(latitude * (Math.PI / 180));
        return 0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);
    }
99837
public Longitude parseLongitude(final String longitudeString)
    throws ParserException
  {
    try
    {
      final Longitude longitude = new Longitude(parseAngle(longitudeString));
      return longitude;
    }
    catch (final RuntimeException e)
    {
      throw new ParserException("Cannot parse longitude: " + longitudeString);
    }

  }
467417
public Double getValue(double latitude, double longitude) {
		CoverageDataRequest request = new CoverageDataRequest(latitude,
				longitude);
		CoverageDataResults values = getValues(request, 1, 1);
		Double value = null;
		if (values != null) {
			value = values.getValues()[0][0];
		}
		return value;
	}
646796
public static String formatLatitude(double latitude, UnitType unit)
    {
        return formatLatitude(Locale.getDefault(), latitude, unit);
    }
556969
public LatLng toLatLng(Point point) {
        point = toWgs84(point);
        LatLng latLng = new LatLng(point.getY(), point.getX());
        return latLng;
    }
660365
private function geocodeQueryString() {
      $queryString = array();

      // One of the following is required.
      $address = $this->getAddress();
      $latitudeLongitude = $this->getLatitudeLongitude();

      // If both are set for some reason, favor address to geocode.
      if ($address) {
        $queryString['address'] = $address;
      }
      elseif ($latitudeLongitude) {
        $queryString['latlng'] = $latitudeLongitude;
      }

      // Optional parameters.
      $queryString['bounds'] = $this->getBounds();
      $queryString['region'] = $this->getRegion();
      $queryString['language'] = $this->getLanguage();
      $queryString['result_type'] = $this->getResultTypeFormatted();
      $queryString['location_type'] = $this->getLocationTypeFormatted();

      // Required.
      $queryString['sensor'] = $this->getSensor();

      // Remove any unset parameters.
      $queryString = array_filter($queryString);

      // The signature is added later using the path + query string.
      if ($this->isBusinessClient()) {
        $queryString['client'] = $this->getClientId();
      }
      elseif ($this->getApiKey()) {
        $queryString['key'] = $this->getApiKey();
      }

      // Convert array to proper query string.
      return http_build_query($queryString);
    }
272834
@Override
    public long convert(int[] input, int inPos) {
        int Y = input[inPos++] & 0xFF;
        int Cb = input[inPos++] & 0xFF;
        int Cr = input[inPos] & 0xFF;

        byte r = (byte) sampleRangeLimitTable[sampleRangeLimitOffset + Y + Cr2R[Cr]];
        byte g = (byte) sampleRangeLimitTable[sampleRangeLimitOffset + Y + ((Cb2G[Cb] + Cr2G[Cr]) >> 16)];

        byte b = (byte) sampleRangeLimitTable[sampleRangeLimitOffset + Y + Cb2B[Cb]];

        return (0xFF000000L | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF));
    }
680021
@Programmatic
    @Override
    public Location getLocation() {
        final String latLng = getLatLng();
        return latLng != null? Location.fromString(latLng.replace(",",";")): null;
    }
633296
public double getX01FromLongitude(double longitude, boolean wrapEnabled) {
		longitude = wrapEnabled ? Clip(longitude, getMinLongitude(), getMaxLongitude()) : longitude;
		final double result = getX01FromLongitude(longitude);
		return wrapEnabled ? Clip(result, 0, 1) : result;
	}
1207845
public static <T> T convert(TypeReference<T> reference, Object value) throws ConvertException{
		return convert(reference.getType(), value, null);
	}
1070921
private GeoPoint getLocation() {

        //sample data
        //{"timestamp": 1483742439, "iss_position": {"latitude": "-50.8416", "longitude": "-41.2701"}, "message": "success"}

        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

        GeoPoint pt = null;
        if (isConnected) {
            try {
                JSONObject jsonObject = json.makeHttpRequest(url_select);
                JSONObject iss_position = (JSONObject) jsonObject.get("iss_position");
                double lat = iss_position.getDouble("latitude");
                double lon = iss_position.getDouble("longitude");
                //valid the data
                if (lat <= 90d && lat >= -90d && lon >= -180d && lon <= 180d) {
                    pt = new GeoPoint(lat, lon);
                } else
                    Log.e(TAG, "invalid lat,lon received");
            } catch (Throwable e) {
                Log.e(TAG, "error fetching json", e);
            }
        }
        return pt;
    }