在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):igaster/laravel_cities开源软件地址(OpenSource Url):https://github.com/igaster/laravel_cities开源编程语言(OpenSource Language):PHP 89.2%开源软件介绍(OpenSource Introduction):IntroductionWhat you get:
What you dont get:
Instructions
The Service provider will be autodiscovered and registered by Laravel. If you are using Laravel version <5.5 then you must manually add the Service Provider in app.php: 'providers' => [
//...
Igaster\LaravelCities\GeoServiceProvider::class,
];
[Tip] Quick script to download on your remote server with:
or otherwise you can use
Download a *.txt files from geonames.org By default it will download allcountries and hierarchy files otherwise you can pass flag --countries for specific countries
you can increase the memory limit for the cli invocation on demand to have process the command at once
So this will increase the memory limit for the command to 8GB with large chunk for each batches You can also pass
by default it is Note: If you don't want all the countries, you can download only country specific files (eg US.txt) and import each one of them with:
Seed with custom dataCreate a json file with custom data at
If an item exists in the DB (based on the 'id' value), then it will be updated else a new entry will be inserted. For example the following json file will rename [
{
"id": 6252001,
"name": "USA"
},
{
"name": "USA Child Item",
"parent_id": 6252001,
"alternames": ["51st State", "dummy name"],
"population": 310232863,
"lat": "39.760000",
"long": "-98.500000"
}
] Please note that adding new items to the DB will reindex ALL items to rebuild the tree structure. Please be patient... An example file is provided: countryNames.json which updates the official country names with a most popular simplified version. Tip: You can get a json representation from the DB by quering the API (see below) Geo Model:You can use $geo->name; // name of geographical point in plain ascii
$geo->alternames; // Array of alternate names (Stored as Json)
$geo->country; // 2-letter country code (ISO-3166)
$geo->id; // Original id from geonames.org database (geonameid)
$geo->population; // Population (Where provided)
$geo->lat; // latitude in decimal degrees (wgs84)
$geo->long; // longitude in decimal degrees (wgs84)
$geo->level; // Administrator level code (feature code)
// parent_id, left, right, depth: Used to build hierarcy tree Visit http://www.geonames.org > Info, for a more detailed description. UsageSearching:use Igaster\LaravelCities\Geo;
Geo::getCountries(); // Get a Collection of all countries
Geo::getCountry('US'); // Get item by Country code
Geo::findName('Nomos Kerkyras'); // Find item by (ascii) name
Geo::searchNames('york'); // Search item by all alternative names. Case insensitive
Geo::searchNames('vegas', Geo::getCountry('US')); // ... and belongs to an item
Geo::getByIds([390903,3175395]); // Get a Collection of items by Ids Traverse tree$children = $geo->getChildren(); // Get direct Children of $geo (Collection)
$parent = $geo->getParent(); // Get single Parent of $geo (Geo)
$ancenstors = $geo->getAncensors(); // Get Ancenstors tree of $geo from top->bottom (Collection)
$descendants = $geo->getDescendants(); // Get all Descentants of $geo alphabetic (Collection) Check Hierarchy Relations:$geo1->isParentOf($geo2); // (Bool) Check if $geo2 is direct Parent of $geo1
$geo2->isChildOf($geo1); // (Bool) Check if $geo2 is direct Child of $geo1
$geo1->isAncenstorOf($geo2); // (Bool) Check if $geo2 is Ancenstor of $geo1
$geo2->isDescendantOf($geo1); // (Bool) Check if $geo2 is Descentant of $geo1 Query scopes (Use them to Build custom queries)Geo::level($level); // Filter by Administration level:
// Geo::LEVEL_COUNTRY, Geo::LEVEL_CAPITAL, Geo::LEVEL_1, Geo::LEVEL_2, Geo::LEVEL_3
Geo::country('US'); // (Shortcut) Items that belongs to country US
Geo::capital(); // (Shortcut) Items that are capitals
Geo::search($name); // Items that conain $name in name OR alternames (Case InSensitive)
Geo::areDescentants($geo); // Items that belong to $geo
$geo->ancenstors(); // Items that contain $geo
$geo->descendants(); // Items that belong to $geo
$geo->children(); // Items that are direct children of $geo
//--Scope usage Examples:
// Get the States of USA in aplhabetic order
Geo::getCountry('US')
->children()
->orderBy('name')
->get();
// Get the 3 biggest cities of Greece
Geo::getCountry('GR')
->level(Geo::LEVEL_3)
->orderBy('population','DESC')
->limit(3)
->get(); If you need more functionality you can extend HTTP APIThis package defines some API routes that can be used to query the DB through simple HTTP requests. To use them insert in your routes file: \Igaster\LaravelCities\Geo::ApiRoutes(); For example if you insert them in your
The response is always a JSON representation of either a Geo class or a Collection. To reduce bandwith, all Geo model attributes will be returned except from
Vue ComponentA Vue component is shipped with this package that plugs into the provided API and provides an interactive way to pick a location through a series of steps. Sorry, no live demo yet, just some screenshots: Step 1: Select your location. Drop down lists loads asynchronous: Step 2: Reached to a destination. Path is displayed and button to edit selection: Step 3: On form submition several fields are beeing submited: Usage GuideAssuming that you are using Webpack to compile your assets, and you have included Add in your applicationIn your main vue-app.js file add the component declaration:
Alternative you may publish the component with
Component will be exported at Compile compoment
Use in blade filesExample: <form action="post-url" method="POST">
<geo-select></geo-select>
<!-- Add more form fields here... -->
<input type="submit">
</form> The following inputs will be submited:
Full syntax:<geo-select
prefix = "geo" <!-- change the fields name prefix -->
api-root-url = "\api" <!-- Root url for API -->
:countries = "[390903,3175395]" <!-- Limit to specific countries (defined by ids) -->
:enable-breadcrumb = "true" <!-- Enable/Disable Breadcrumb -->
></geo-select> |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论