@param LatLon $latlon
@param string|integer $distance In miles

@return LatLonRange

@throws GeocodingException
762169
public static function create_from_distance( $latlon, $distance ) {
    if ( ! ( $latlon instanceof LatLon ) ) {
      throw new GeocodingException( '$latlon parameter is not a LatLon object.' );
    }

    if ( ! Utils::validate_distance( $distance ) ) {
      throw new GeocodingException( 'Distance value is invalid: ' . $distance );
    }
    $distance = (string) $distance;

    // Calculate the bounding box on the globe.
    $center = \AnthonyMartin\GeoLocation\GeoLocation::fromDegrees( $latlon->get_lat(), $latlon->get_lon() );
    $bounds = $center->boundingCoordinates( $distance, 'miles' );

    $min = new LatLon( $bounds[0]->getLatitudeInDegrees(), $bounds[0]->getLongitudeInDegrees() );
    $max = new LatLon( $bounds[1]->getLatitudeInDegrees(), $bounds[1]->getLongitudeInDegrees() );

    return new LatLonRange( $min, $max );
  }
461443
public function between(LatLong $pointA, LatLong $pointB)
    {
        if (!empty($this->points)) {
            throw new \RuntimeException('The between() method can only be called when it is the first set or co-ordinates.');
        }
        $this->addPoint($pointA);
        $this->addPoint($pointB);
        return $this;
    }
467335
public Query queryUsersWithinLocation(float distance, float lattitude,
            float longitude, String ql) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("ql",
                this.makeLocationQL(distance, lattitude, longitude, ql));
        Query q = queryEntitiesRequest(HttpMethod.GET, params, null, organizationId,
                applicationId, "users");
        return q;
    }
968200
public function geoDistance($field, $distance, $location, array $attributes = [])
    {
        $query = new GeoDistanceQuery($field, $distance, $location, $attributes);

        $this->append($query);

        return $this;
    }
459813
public static function fromString($native, $separator = ',')
    {
        $values = explode($separator, $native, 4);

        if (count($values) !== 4) {
            throw new \InvalidArgumentException(
                sprintf('LatLngBounds can not be created from string "%s"', $native)
            );
        }

        return new LatLngBounds(
            new LatLng($values[0], $values[1]),
            new LatLng($values[2], $values[3])
        );
    }
680221
public function nearPointSpherical($field, $longitude, $latitude, $distance)
    {
        $point = new Point(array(
            (float) $longitude,
            (float) $latitude
        ));

        $near = array(
            '$geometry' => $point->jsonSerialize(),
        );

        if (is_array($distance)) {
            if (!empty($distance[0])) {
                $near['$minDistance'] = (int) $distance[0];
            }
            if (!empty($distance[1])) {
                $near['$maxDistance'] = (int) $distance[1];
            }
        } else {
            $near['$maxDistance'] = (int) $distance;
        }

        $this->where($field, array('$nearSphere' => $near));

        return $this;
    }
541197
public static function LL2Utm( string $ellipsoid, $lat, $long )
   {

      if ( ! isset( Ellipsoid::$Ellipsoid[ $ellipsoid ] ) )
      {
         // The defined ellipsoid does not exist.
         return false;
      }

      // Get the longitude decimal value
      $ln = ( ( $long instanceof AbstractElement )
         ? $long->getDecimalValue()
         : ( \is_double( $long ) ? $long : \doubleval( $long ) )
      );

      // Get the latitude decimal value
      $lt = ( ( $lat instanceof AbstractElement )
         ? $lat->getDecimalValue()
         : ( \is_double( $lat ) ? $lat : \doubleval( $lat ) )
      );

      // Init some required parameters
      $longOrigin      = null;
      $eccPrimeSquared = null;
      $longOriginRad   = null;
      $k0              = 0.9996;

      // Doing the calculation
      $a               = Ellipsoid::$Ellipsoid[ $ellipsoid ][ 0 ];
      $eccSquared      = Ellipsoid::$Ellipsoid[ $ellipsoid ][ 1 ];
      $N = null; $T = null; $C = null; $A = null; $M = null;
      $longTemp        = ( $ln + 180.0 ) - \intval( ( $ln + 180 ) / 360 ) * 360 - 180;
      $latRad          = $lt * self::DEG2RAD;
      $longRad         = $longTemp * self::DEG2RAD;
      $zoneNumber      = \intval( ( $longTemp + 180 ) / 6 ) + 1;

      if ( $lt >= 56.0 && $lt < 64.0 && $longTemp >= 3.0 && $longTemp < 12.0 )
      {
         $zoneNumber = 32;
      }

      if ( $lt >= 72.0 && $lt < 84.0 )
      {
         if ( $longTemp >= 0.0  && $longTemp <  9.0 )
         {
            $zoneNumber = 31;
         }
         else if ( $longTemp >= 9.0  && $longTemp < 22.0 )
         {
            $zoneNumber = 33;
         }
         else if ( $longTemp >= 22.0 && $longTemp < 33.0 )
         {
            $zoneNumber = 35;
         }
         else if ( $longTemp >= 33.0 && $longTemp < 42.0 )
         {
            $zoneNumber = 37;
         }
      }

      $longOrigin    = ( $zoneNumber - 1 ) * 6 - 180 + 3;
      $longOriginRad = $longOrigin * self::DEG2RAD;
      $UTMZone       = \sprintf(
         '%d%s',
         $zoneNumber,
         self::UTMLetterDesignator($lt)
      );

      $eccPrimeSquared = ( $eccSquared ) / ( 1 - $eccSquared );
      $N               = $a / \sqrt( 1 - $eccSquared * \sin( $latRad ) * \sin( $latRad ) );
      $T               = \tan( $latRad ) * \tan( $latRad );
      $C               = $eccPrimeSquared * \cos( $latRad ) * \cos( $latRad );
      $A               = \cos( $latRad ) * ( $longRad - $longOriginRad );
      $M               = $a * (
            ( 1 - $eccSquared/4 - 3 * $eccSquared * $eccSquared/64 - 5 * $eccSquared * $eccSquared * $eccSquared / 256 )
            * $latRad
            - (3 * $eccSquared/8 + 3 * $eccSquared * $eccSquared/32 + 45 * $eccSquared * $eccSquared * $eccSquared/1024)
              * \sin( 2 * $latRad )
            + ( 15 * $eccSquared * $eccSquared / 256 + 45 * $eccSquared * $eccSquared * $eccSquared / 1024 )
              * \sin( 4 * $latRad )
            - ( 35 * $eccSquared * $eccSquared * $eccSquared / 3072) * \sin( 6 * $latRad )
         );

      $UTMEasting = (double) ( $k0 * $N * ( $A + ( 1 - $T + $C ) * $A * $A * $A / 6
                                            + ( 5 - 18 * $T + $T * $T + 72 * $C - 58 * $eccPrimeSquared )
                                              * $A * $A * $A * $A * $A / 120 ) + 500000.0
      );
      $UTMEasting = \round( $UTMEasting, 0 );
      $UTMNorthing = (double) ( $k0
                                * ( $M + $N * \tan( $latRad ) * ( $A * $A / 2 + ( 5 - $T + 9 * $C + 4 * $C * $C )
                                                                                * $A * $A * $A * $A / 24 + ( 61 - 58 * $T + $T * $T + 600 * $C - 330 * $eccPrimeSquared )
                                                                                                           * $A * $A * $A * $A * $A * $A / 720 ) )
      );

      if ( $lt < 0 )
      {
         $UTMNorthing += 10000000.0;
      }

      $UTMNorthing = \round( $UTMNorthing, 0 );

      return "{$UTMZone} E {$UTMEasting} N {$UTMNorthing}";

   }
291836
public function coordinatesDistance($lat1, $lng1, $lat2, $lng2, $miles = false)
    {
        $pi80 = M_PI / 180;
        $lat1 *= $pi80;
        $lng1 *= $pi80;
        $lat2 *= $pi80;
        $lng2 *= $pi80;

        $r = 6372.797;
        $dlat = $lat2 - $lat1;
        $dlng = $lng2 - $lng1;

        $a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2);
        $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
        $km = $r * $c;

        return $miles ? ($km * 0.621371192) : $km;
    }
141771
def latlon_round(latlon, spacing=1000):
    ''''''
    g = latlon_to_grid(latlon)
    g.easting = (g.easting // spacing) * spacing
    g.northing = (g.northing // spacing) * spacing
    return g.latlon()
67116
public function moveInRandomDirection(\Tx_Oelib_Interface_Geo $object, $distance)
    {
        $direction = \mt_rand(0, 360);
        $this->move($object, $direction, $distance);
    }
635519
function (latlon) {
        return {
            x: latlon.lng * 6378137 * Math.PI / 180,
            y: Math.log(Math.tan((90 + latlon.lat) * Math.PI / 360)) * 6378137
        };
    }
856394
public function addCoord(LatLng $coord)
    {
        $cloned = clone $coord;
        $cloned->setName(null);
        $this->options['data'][] = $coord;

        return $this;
    }
1186531
def distance_to(self, address, measure="Miles", httpclient=None):
        
        if isinstance(address, Address) and self.latlng and address.latlng:
            lat1, lon1 = map(float, self.latlng)
            lat2, lon2 = map(float, address.latlng)
        elif self.latlng and type(address) is tuple:
            lat1, lon1 = map(float, self.latlng)
            lat2, lon2 = address
        else:
            raise ValueError(":address must be type tuple or Address")
            
        radius = 6371 # km          
        dlat = math.radians(lat2 - lat1)
        dlon = math.radians(lon2 - lon1)
        a = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(math.radians(lat1)) \
          * math.cos(math.radians(lat2)) * math.sin(dlon / 2) * math.sin(dlon / 2)
        c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
        d = radius * c
        # d is in kilometers
        if measure == self.KILOMETERS:
            return d
        elif measure == self.METERS:
            return d / 1000
        elif measure == self.MILES:
            return d * .621371
        else:
            return d
742067
def distance_to(other)
      if other.class == LatLon
        other = UTM::latlon_to_utm other, :ellipsoid => @ellipsoid, :zone => @zone
      end
      unless other.zone == @zone
        raise GeoUtmException, 'Cannot calc distance for points in different zones - convert first'
      end
      Math::sqrt((@n - other.n) ** 2.0 + (@e - other.e) ** 2.0) 
    end
1020436
public function whereLocation($lat, $long, $distance_in_meters = 10000)
	{
		$this->query = $this->index->addConditionToQuery($this->query, array(
			'lat'      => $lat,
			'long'     => $long,
			'distance' => $distance_in_meters,
		));
		
		return $this;
	}
28286
public function searchByLocation($lat, $long){
        if($lat != null && $long != null){
            $this->addParam("lat", $lat);
            $this->addParam("lng", $long);
        }
    }
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
				);
		}
	}