Download the PHP package birgir/geo-query without Composer

On this page you can find all versions of the php package birgir/geo-query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package geo-query

WordPress plugin: Geo Query

Build Status GitHub license Packagist

Description

This plugin adds a support for the geo_query part of the WP_Query and WP_User_Query.

Supports geo data stored in post/user meta or in a custom table.

It uses the Haversine SQL implementation by Ollie Jones (see here).

The plugin works on PHP 5.3+.

It supports the GitHub Updater.

Activate the plugin and you can use the geo_query parameter in all your WP_Query and WP_User_Query queries.

Few examples are here below, e.g. for the Rest API.

Installation

Upload the plugin to the plugin folder and activate it.

To install dependencies with Composer (not required):

composer install

or

php composer.phar install

within our folder. See here for more information on how to install Composer.

Then play with the example below, in your theme or in a plugin.

Have fun ;-)

Example - Basic WP_Query usage:

Here's an example of the default input parameters of the geo_query part:

$args = [
    'post_type'           => 'post',    
    'posts_per_page'      => 10,
    'ignore_sticky_posts' => true,
    'orderby'             => [ 'title' => 'DESC' ],
    'geo_query'           => [
        'lat'                =>  64,                                // Latitude point
        'lng'                =>  -22,                               // Longitude point
        'lat_meta_key'       =>  'geo_lat',                         // Meta-key for the latitude data
        'lng_meta_key'       =>  'geo_lng',                         // Meta-key for the longitude data 
        'radius'             =>  150,                               // Find locations within a given radius (km)
        'order'              =>  'DESC',                            // Order by distance
        'distance_unit'      =>  111.045,                           // Default distance unit (km per degree). Use 69.0 for statute miles per degree.
        'context'            => '\\Birgir\\Geo\\GeoQueryHaversine', // Default implementation, you can use your own here instead.
    ],
];
$query = new WP_Query( $args );

Example - Rest API usage:

Here's a modified example from @florianweich:

add_filter( 'rest_query_vars', function ( $valid_vars ) {
    return array_merge( $valid_vars, [ 'geo_location' ] );
} );

add_filter( 'rest_post_query', function( $args, $request ) {
    $geo = json_decode( $request->get_param( 'geo_location' ) );
    if ( isset( $geo->lat, $geo->lng ) ) {
        $args['geo_query'] = [
            'lat'                =>  (float) $geo->lat,
            'lng'                =>  (float) $geo->lng,
            'lat_meta_key'       =>  'geo_lat',
            'lng_meta_key'       =>  'geo_lng',
            'radius'             =>  ($geo->radius) ? (float) $geo->radius : 50,
        ];
    }
    return $args;
}, 10, 2 );

Test it with e.g.:

https://example.com/wp-json/wp/v2/posts?geo_location={"lat":"64.128288","lng":"-21.827774","radius":"50"}

One can use rest_{custom-post-type-slug}_query filter for a custom post type.

Example - Basic WP_User_Query usage:

Here's an example from @acobster:

$args = [
  'role'      => 'subscriber',
  'geo_query' => [
    'lat'          => 47.236,
    'lng'          => -122.435,
    'lat_meta_key' => 'geo_lat',
    'lng_meta_key' => 'geo_lng',
    'radius'       => 1,
    'context'      => '\\Birgir\\Geo\\GeoQueryUserHaversine',
  ],
];

$query = new WP_User_Query( $args );

Example - Basic WP_Query usage for fetching lat/lng data from a custom table with Haversine formula:

$args = array(
    'post_type'           => 'post',    
    'posts_per_page'      => 10,
    'ignore_sticky_posts' => true,
    'orderby'             => array( 'title' => 'DESC' ),            
    'geo_query' => array(
        'table'         => 'custom_table', // Table name for the geo custom table.
        'pid_col'       => 'pid',          // Column name for the post ID data
        'lat_col'       => 'lat',          // Column name for the latitude data
        'lng_col'       => 'lng',          // Column name for the longitude data 
        'lat'           => 64.0,           // Latitude point
        'lng'           => -22.0,          // Longitude point
        'radius'        => 1,              // Find locations within a given radius (km)
        'order'         => 'DESC',         // Order by distance
        'distance_unit' => 111.045,        // Default distance unit (km per degree). Use 69.0 for statute miles per degree.
        'context'       => '\\Birgir\\Geo\\GeoQueryPostCustomTableHaversine', // Custom table implementation, you can use your own here instead.
    ),
);

$query = new WP_Query( $args );

Check the unit test method test_custom_table_in_wp_query() as a more detailed example.

Notes on the parameters:

Feedback

Any suggestions are welcomed.

Changelog

0.2.2 (2024-01-05)

0.2.1 (2023-07-26)

0.2.0 (2020-04-25)

0.1.1 (2019-01-23)

0.1.0 (2018-08-06)

0.0.7 (2018-06-27)

0.0.6 (2017-11-16)

0.0.5 (2017-02-26)

0.0.4 (2017-02-26)

0.0.3 (2015-04-29)

0.0.2 (2015-03-10)

0.0.1 - Init


All versions of geo-query with dependencies

PHP Build Version
Package Version
Requires composer/installers Version ^1.0.0
php Version >=5.3.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package birgir/geo-query contains the following files

Loading the files please wait ....