A map sdk

2.1.1 2018-12-24 06:45 UTC

This package is auto-updated.

Last update: 2024-09-24 21:12:05 UTC


README

A map sdk for getting Geo Code and Geo-Fencing.

Installing

$ composer require rainsens/map -vvv

Configuration

You have to get the API Key from Amap before use.

Usage

use Rainsens\Map\Map;
$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$map = new Map($key);

Getting one geocoding once

$map->GeoCode->get('北京市朝阳区阜通东大街6号', '北京');
$map->GeoCode->get('北京市朝阳区阜通东大街6号', '北京', 'json');
$map->GeoCode->get('北京市朝阳区阜通东大街6号', '北京', 'xml');

Getting multi geocoding once

$cities = [
    '北京市朝阳区阜通东大街6号',
    '北京市通州区运河东大街6号',
];

$map->GeoCode->get($cities, '北京');

Example

"status": "1",
"info": "OK",
"infocode": "10000",
"count": "1",
"geocodes": [
    {
        "formatted_address": "北京市朝阳区阜通东大街|6号",
        "country": "中国",
        "province": "北京市",
        "citycode": "010",
        "city": "北京市",
        "district": "朝阳区",
        "township": [],
        "neighborhood": {
            "name": [],
            "type": []
        },
        "building": {
            "name": [],
            "type": []
        },
        "adcode": "110105",
        "street": "阜通东大街",
        "number": "6号",
        "location": "116.483038,39.990633",
        "level": "门牌号"
    }
]
<response>
    <status>1</status>
    <info>OK</info>
    <infocode>10000</infocode>
    <count>1</count>
    <geocodes type="list">
        <geocode>
            <formatted_address>北京市朝阳区阜通东大街|6号</formatted_address>
            <country>中国</country>
            <province>北京市</province>
            <citycode>010</citycode>
            <city>北京市</city>
            <district>朝阳区</district>
            <township></township>
            <neighborhood>
                <name></name>
                <type></type>
            </neighborhood>
            <building>
                <name></name>
                <type></type>
            </building>
            <adcode>110105</adcode>
            <street>阜通东大街</street>
            <number>6号</number>
            <location>116.483038,39.990633</location>
            <level>门牌号</level>
        </geocode>
    </geocodes>
</response>

About Geo-Fencing

About arguments please refer AMap.

$map->geoFence()->create([...]);
$map->geoFence()->search([...]);
$map->geoFence()->update([...]);
$map->geoFence()->enable(string $gid, bool $status = true);
$map->geoFence()->delete(string $gid);
$map->geoFence()->monitor([...]);

Using in Laravel

Install with the same way and put the API Key in config/services.php

    .
    .
    .
     'map' => [
        'key' => env('MAP_API_KEY'),
    ],

Then configure the MAP_API_KEY in .env

MAP_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Map::geoCode->get('北京市朝阳区阜通东大街6号', '北京');
Map::geoFence()->create([...]);
Map::geoFence()->search([...]);
Map::geoFence()->update([...]);
Map::geoFence()->enable(string $gid, bool $status = true);
Map::geoFence()->delete(string $gid);
Map::geoFence()->monitor([...]);

About arguments above please refer AMap.

Reference

Amap

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

License

MIT