定制 barikoi/barikoiapis 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

barikoi/barikoiapis

Composer 安装命令:

composer require barikoi/barikoiapis

包简介

A comprehensive Laravel package for integrating Barikoi API - Bangladesh's leading location data provider

README 文档

README

A comprehensive Laravel package for integrating Barikoi API - Bangladesh's leading location data provider.

License: MIT

Features

  • 🗺️ Location Services: Geocoding, Reverse Geocoding, Autocomplete, Place Search, Place Details, Nearby Places, Check nearby location within a specified radius, Snap to Road
  • 🛣️ Routing: Calculate Detailed Route and Route Overview
  • ⚠️ Error Handling: User-friendly exceptions with actionable error messages

Installation

composer require barikoi/barikoiapis

Configuration

  1. Publish the configuration file:
php artisan vendor:publish --provider="Barikoi\BarikoiApis\BarikoiServiceProvider" --tag="config"
  1. Add your Barikoi API credentials to .env:
BARIKOI_API_KEY=your_api_key_here

Get your API key from Barikoi.

Quick Start

use Barikoi\BarikoiApis\Facades\Barikoi;

// 1. Reverse geocoding with rich options
$options = [
    'country_code' => 'BD',
    'district' => true,
    'post_code' => true,
    'country' => true,
    'sub_district' => true,
    'union' => true,
    'pauroshova' => true,
    'location_type' => true,
    'division' => true,
    'address' => true,
    'area' => true,
    'bangla' => true,
    'thana' => true,
];
$reverse = Barikoi::reverseGeocode(90.3572, 23.8067, $options);

$autocomplete=Barikoi::autocomplete('barikoi', [
                'bangla'       => true,
                'city'         => 'dhaka',
                'sub_area'     => true,
                'sub_district' => true,
            ]);

// Geocode (Rupantor) - returns stdClass (object)
$geocoded = Barikoi::geocode('shawrapara');

// Search place by text
$places = Barikoi::searchPlace('Dhanmondi');

// Get place details by place_code - returns stdClass (object)
$placeDetails = Barikoi::placeDetails('BKOI2017', [
    'session_id' => '4c47157f-22d6-4689-abdf-c9f81eb43ae4'
]);

// Nearby search
$nearby = Barikoi::nearby(90.38305163, 23.87188719, 0.5, 2);

// Check nearby (geofence check)
$checkNearby = Barikoi::checkNearby(23.8067, 90.3572, 23.8070, 90.3575, 50);

// Snap to nearest road
$snapped = Barikoi::snapToRoad(23.8067, 90.3572);

// Detailed route between two points (returns stdClass object with "trip")
$route = Barikoi::calculateRoute([
    'start' => ['longitude' => 90.36558776260725, 'latitude' => 23.791645065364126],
    'destination' => ['longitude' => 90.3676300089066, 'latitude' => 23.784715477921843],
], [
    'type' => 'vh',           // 'vh' (motorcycle only) or 'gh' (all profiles)
    'profile' => 'motorcycle'  // 'bike', 'motorcycle', or 'car'
]);

// Simple route overview (returns stdClass object)
$overview = Barikoi::routeOverview([
    ['longitude' => 90.3572, 'latitude' => 23.8067],
    ['longitude' => 90.3680, 'latitude' => 23.8100],
], [
    'profile' => 'car',
    'geometries' => 'polyline',
]);

Documentation

📚 API Documentation

Complete documentation with parameters, conditions, and error handling for each API:

API Service Documentation
Location Services docs/location-api.md
- Reverse Geocoding Convert coordinates to address
- Geocoding (Rupantor) Convert address to coordinates
- Autocomplete Place suggestions
- Search Place Text-based place search
- Place Details Get Place Details
- Nearby Search Find places within radius
- Check Nearby Check nearby location within a specified radius
- Snap to Road Correct GPS coordinates
Routing Services docs/routing-api.md
- Route Overview Simple route calculation
- Detailed Route Turn-by-turn route with options

Usage

Using Facade (Recommended)

use Barikoi\BarikoiApis\Facades\Barikoi;

$reverse = Barikoi::reverseGeocode(90.3572, 23.8067); // returns stdClass (object)
$places = Barikoi::autocomplete('restaurant');

Error Handling

The package provides comprehensive error handling with user-friendly messages.

Exception Types

BarikoiValidationException - Validation errors (400)

  • Invalid coordinates
  • Missing parameters
  • Invalid input values

BarikoiApiException - API errors (401, 404, 429, 500, etc.)

  • 401: Invalid API key
  • 404: Resource not found
  • 429: Rate limit exceeded
  • 500: Server error

Basic Usage

use Barikoi\BarikoiApis\Facades\Barikoi;
use Barikoi\BarikoiApis\Exceptions\BarikoiApiException;
use Barikoi\BarikoiApis\Exceptions\BarikoiValidationException;

try {
    $result = Barikoi::reverseGeocode(90.3572, 23.8067);

} catch (BarikoiValidationException $e) {
    // Handle validation errors (400)
    echo "Invalid input: " . $e->getMessage();

} catch (BarikoiApiException $e) {
    // Handle API errors (401, 404, 500, etc.)
    echo "API Error: " . $e->getMessage();
}

Error Messages

Code Message
400 Validation Error: Invalid coordinates. Please check your input parameters.
401 Authentication Failed: Invalid API key. Please verify your API key is correct.
404 Not Found: Resource not found. The requested resource or endpoint does not exist.
429 Rate Limit Exceeded: Too many requests. Please reduce the number of requests...
500 Server Error: Internal Server Error. The Barikoi API is experiencing issues...

Getting Error Details

catch (BarikoiValidationException $e) {
    $message = $e->getMessage();              // User-friendly message
    $statusCode = $e->getCode();              // HTTP status code
}

See individual API documentation for specific error conditions and solutions.

Examples

Example 1: Get Address from GPS

public function getAddress(Request $request)
{
    try {
        $result = Barikoi::reverseGeocode(
            $request->longitude,
            $request->latitude,
            ['district' => true, 'bangla' => true]
        );

        return response()->json([
            'address' => $result->place->address,
            'district' => $result->place->district,
        ]);
    } catch (BarikoiApiException $e) {
        return response()->json(['error' => $e->getMessage()], $e->getCode());
    }
}

Example 2: Calculate Route

public function calculateRoute(Request $request)
{
    try {
        $route = Barikoi::calculateRoute([
            'start' => ['longitude' => $request->start_longitude, 'latitude' => $request->start_latitude],
            'destination' => ['longitude' => $request->destination_longitude, 'latitude' => $request->destination_latitude],
        ], [
            'type' => 'vh',
            'profile' => 'motorcycle'
        ]);

        return $route;
    } catch (BarikoiApiException $e) {
        return response()->json(['error' => 'Route calculation failed'], 500);
    }
}

API Reference

For detailed Barikoi API documentation, visit Barikoi API Documentation.

Changelog

See CHANGELOG.md for version history.

License

The MIT License (MIT). See License File for more information.

Credits

Support

For issues or questions:

  • Create an issue on GitHub
  • Check the detailed API documentation in docs/ folder
  • Contact support@barikoi.com for any support

barikoi/barikoiapis 适用场景与选型建议

barikoi/barikoiapis 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 172 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「routing」 「geocoding」 「maps」 「laravel」 「location」 「bangladesh」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 barikoi/barikoiapis 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 barikoi/barikoiapis 我们能提供哪些服务?
定制开发 / 二次开发

基于 barikoi/barikoiapis 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 172
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-06