get nearby location by coordinate from eloquent laravel

Overview

LARAVEL-COORDINATE

get nearby location data from database with eloquent laravel

Installation

composer require bagusindrayana/laravel-coordinate

  • In Model
#use trait
use Bagusindrayana\LaravelCoordinate\Traits\LaravelCoordinate;

class Toko extends Model
{
    use LaravelCoordinate;

    //optional
    public $_latitudeName = "latitude_column"; //default name is latitude
    public $_longitudeName = "latitude_column"; //default name is longitude

    //

}
  • Using trait
    //get data by distance 500 m (0.5KM)
    $tokos = Toko::nearby([
        -0.497493,//latitude
        117.156480//longitude
    ],0.5)->get();


    //using order remember order awlways in last query
    //get data by distance 1 KM and order by farthest distance
    $tokos = Toko::nearby([
        -0.497493,//latitude
        117.156480//longitude
    ],1)->farthest()->get();
    
    //get data by distance 1 KM and order by closest distance
    $tokos = Toko::nearby([
        -0.497493,//latitude
        117.156480//longitude
    ],1)->closest()->get();
    
    //add new column with containt distance value
    $tokos = Toko::nearby([
        -0.497493,//latitude
        117.156480//longitude
    ],0.5) //0.5 Km
    ->selectDistance(['id','nama_toko'],'_distance') //will add new column with name _distance contain value of distance every record
    ->get();

Formula

I haven't tried how much data it can handle and how fast the calculations are so here are 3 different formulas you can try

formula paramter/arguments (int)

  • 0 = default
  • 1 = Spherical Law of Cosines
  • 2 = Haversine formula

example :

$tokos = Toko::nearby([
        -0.497493,//latitude
        117.156480//longitude
    ],
    0.5,
    1//using Spherical Law of Cosines
)
->get();

Scope

nearby(coordinate,radius/distance = 5,formula = 0)
closest(coordinate,formula = 0)
farthest(coordinate,formula = 0)
selectDistance(fieldName,aliasName,formula = 0)
insideBox(coorinate(2 coordinate))
You might also like...
Picasso is a Laravel Image Management and Optimization Package

Picasso is a Laravel Image Management and Optimization Package. Define image dimensions and options, store uploaded image in multiple dimensions with or without a watermark and retrieve optimized images on your website when needed.

This is an image manipulation REST API written in PHP Laravel Framework

Laravel Image Manipulation REST API Demo Here is fully working Demo: https://www.lobiimages.com/ You have to register first in order to generate acces

A Laravel Gravatar package for retrieving gravatar image URLs or checking the existance of an image.

Gravatar for Laravel 5.x, 6, 7 and 8 Installation First, pull in the package through Composer via the command line: composer require creativeorange/gr

Laravel package a helper to Generate the QR code and signed it for ZATCA E-invoicing

Laravel ZATCA E-invoicing Introduction Laravel package a helper to Generate the QR code and signed it for ZATCA E-invoicing Installation To get the la

🤹‍♀️Very simple to use Gravatar implementation for Laravel
🤹‍♀️Very simple to use Gravatar implementation for Laravel

Very simple to use Gravatar implementation for Laravel. Install, Include the Facade and then generate, simple! Installation You can install the packag

This is a Location Registration For location registration

location-registration-system This is a Location Registration location-registration-system for users registration location if your location verifide Wi

A Laravel (php) package to interface with the geo-location services at geonames.org.

geonames v7.x A Laravel (php) package to interface with the geo-location services at geonames.org. Major Version Jump I jumped several major versions

Determine the geographical location of website visitors based on their IP addresses.

GeoIP for Laravel Determine the geographical location and currency of website visitors based on their IP addresses. GeoIP for Laravel on Packagist Geo

A simple way to deploy your application to a remote location.

Deploy Plugin A simple way to deploy your application to a remote location. Currently in Active Development This plugin is incomplete. This plugin is

PHP library for determining the physical location of binaries

Bin Locator Library for searching binary files in the operating system. Requirements PHP = 7.4 Installation Library is available as composer reposito

Server manager is a open source project made for people so that they can add the servers to one single place irrespective of their provider and manage it through one location.
Server manager is a open source project made for people so that they can add the servers to one single place irrespective of their provider and manage it through one location.

Server Manager Are you sick of having to log into hundreads of different website just to access your server? Well we got you, Server manager is a open

A simple script i made that generate a valid http(s) proxy in json format with its geo-location info

Gev Proxy Generator GPG is a simple PHP script that generate a proxy using free services on the web, the proxy is HTTP(s) and it generate it in json f

Ip2region is a offline IP location library with accuracy rate of 99.9% and 0.0x millseconds searching performance. DB file is ONLY a few megabytes with all IP address stored. binding for Java,PHP,C,Python,Nodejs,Golang,C#,lua. Binary,B-tree,Memory searching algorithm

Ip2region是什么? ip2region - 准确率99.9%的离线IP地址定位库,0.0x毫秒级查询,ip2region.db数据库只有数MB,提供了java,php,c,python,nodejs,golang,c#等查询绑定和Binary,B树,内存三种查询算法。 Ip2region特性

Determine the geographical location of website visitors based on their IP addresses.

Determine the geographical location and currency of website visitors based on their IP addresses.

Ssibrahimbas location-app
Ssibrahimbas location-app

Ssibrahimbas location-app With this API you can currently add, list, filter, delete and update countries and cities. Endpoints Create Country You can

DomainMOD is an open source application written in PHP & MySQL used to manage your domains and other internet assets in a central location
DomainMOD is an open source application written in PHP & MySQL used to manage your domains and other internet assets in a central location

DomainMOD is an open source application written in PHP & MySQL used to manage your domains and other internet assets in a central location. DomainMOD also includes a Data Warehouse framework that allows you to import your web server data so that you can view, export, and report on your live data.

Collection of the Laravel/Eloquent Model classes that allows you to get data directly from a Magento 2 database.

Laragento LAravel MAgento Micro services Magento 2 has legacy code based on abandoned Zend Framework 1 with really ugly ORM on top of outdated Zend_DB

A helpful Laravel package to help me get started in Laravel projects quicker.

Launchpad A helpful Laravel package to help me get started in Laravel projects quicker. This is still a work in progress, so use at your own risk! CLI

Get started with Laravel 5.3 and AngularJS (material)
Get started with Laravel 5.3 and AngularJS (material)

Laravel 5.3 Angular Material Starter Demo An online demo is available. Angular (2+) update While this starter used to be an excellent starting point f

Releases(0.0.3)
Owner
Bagus Indrayana
hublaaaaaaaaaaaaaaaaaaaa
Bagus Indrayana
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image

Laravel ImageUp The qcod/laravel-imageup is a trait which gives you auto upload, resize and crop for image feature with tons of customization. Install

QCode.in 708 Dec 22, 2022
This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files.

Laravel FFMpeg This package provides an integration with FFmpeg for Laravel 6.0 and higher. Laravel's Filesystem handles the storage of the files. Fea

Protone Media 1.3k Jan 7, 2023
Laragram is a simple instagram "clone" built with Laravel and Tailwind CSS

Laragram is a simple instagram "clone" built with Laravel and Tailwind CSS that gives to the users the ability to create or edit their own profiles (including profile image and description), upload images and share them among friends

null 0 Jul 24, 2021
Laravel Qcloud Content Security T-Sec 腾讯云内容安全(文字图片内容审核)服务

Laravel Qcloud Content Security T-Sec 天御内容安全服务使用了深度学习技术,识别文本/图片中出现的可能令人反感、不安全或不适宜内容,支持用户配置词库/图片黑名单,识别自定义的识别类型。

安正超 34 Jun 20, 2022
An open source image hosting service powered by Laravel

Limg An open source image hosting service powered by Laravel Features Upload your image via file, url or ShareX ! Manage your image (custom title, pub

Thomas 56 Dec 16, 2022
An easy-to-use PHP QrCode generator with first-party support for Laravel.

An easy-to-use PHP QrCode generator with first-party support for Laravel.

Simple Software LLC 2.2k Jan 5, 2023
Optimize your images on the fly with Glide for Laravel.

Glide for Laravel Optimize your images on the fly with Glide for Laravel. Support us Like our work? You can support us by purchasing one of our produc

Flowframe 53 Oct 17, 2022
Laravel Package for making thumbnails instantly

Laravel Thumbnail Generator Package for uploading the image and saving that image along with it's thumbnail. What does it do ? Uploads Image Make its

DRH2SO4 50 Dec 5, 2022
Laravel Optical Character Reader(OCR) package using ocr engines like Tesseract

LaraOCR Laravel Optical Character Reader(OCR) package using ocr engines like Tesseract under the hood. Features Read text from image using WebUI/Progr

Al Imran Ahmed 100 Jan 4, 2023
Laravel Favicon - Create dynamic favicons based on your environment settings.

Laravel Favicon Create dynamic favicons based on your environment settings. Laravel Package Development If you want to learn how to create reusable PH

Beyond Code 320 Dec 12, 2022