Country::class includes a variety of PHP functions. Many of these functions are used by the package itself; however, you are free to use them in your own applications if you find them convenient.
The Country::class offers a variety of functions that provide quick access to $this->coordinates, allowing you to retrieve geographical data rapidly. Many of these functions are used internally by the package, but you are free to utilize them in your own applications for convenience.
To start working with the CountryCoordinates::class model, you can use the following code:
use Lwwcas\LaravelCountries\Models\CountryCoordinates;
$geoData = CountryCoordinates::all();
This will return all geographical records available, including information such as latitude, longitude, and altitude.
The CountryCoordinates data is designed to be seamlessly integrated with country-specific information.
use Lwwcas\LaravelCountries\Models\CountryCoordinates;
$coordinates = CountryCoordinates::inRandomOrder()->first();
$country = $coordinates->country()->first();
$latitude = $coordinates->latitude;
// 41.3275
or directly
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$latitude = $country->latitude();
// 41.3275
Retrieves the latitude of the country in decimal degrees.
->latitude()
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->latitude();
Retrieves the longitude of the country in decimal degrees.
->longitude()
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->longitude();
Retrieves an array with both latitude and longitude in decimal degrees.
->coordinatesInDecimal()
::: code-group
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->coordinatesInDecimal();
[
'latitude' => 42.5063,
'longitude' => 1.5218,
];
:::
Retrieves the coordinates in degrees with decimal minutes.
->coordinatesInDegreesWithDecimal()
->coordinatesInDD()
::: code-group
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->coordinatesInDegreesWithDecimal();
// or
$country->coordinatesInDD();
(string) 42.5063° N, 1.5218° E
:::
Retrieves the coordinates in degrees, minutes, and seconds (DMS) format.
->coordinatesInDegreesMinutesSeconds()
->coordinatesInDMS()
::: code-group
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->coordinatesInDegreesMinutesSeconds();
// or
$country->coordinatesInDMS();
(string) 42°30'22.68" N, 1°31'18.48" E
:::
Retrieves the coordinates in degrees and decimal minutes format.
->coordinatesInDegreesAndDecimalMinutes()
->coordinatesInDDM()
::: code-group
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->coordinatesInDegreesAndDecimalMinutes();
// or
$country->coordinatesInDDM();
(string) 42°30.378' N, 1°31.308' E
:::
Checks if the country is in the Northern Hemisphere.
->isInNorthernHemisphere()
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->isInNorthernHemisphere();
// True or False
Checks if the country is in the Southern Hemisphere.
->isInSouthernHemisphere()
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->isInSouthernHemisphere();
// True or False
Retrieves the coordinates in KML (Keyhole Markup Language) format.
->coordinatesInKLM()
::: code-group
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->coordinatesInKLM();
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Republic of Guinea-Bissau</name>
<description>11.8037,-15.1804</description>
<Point>
<coordinates>-15.1804,11.8037</coordinates>
</Point>
</Placemark>
</kml>
:::
Retrieves the coordinates in geo tags format.
->coordinatesInGeoTags()
::: code-group
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->coordinatesInGeoTags();
geotagged
geo:lat=35.126400
geo:lon=33.429900
:::
Retrieves the coordinates in the format of an ICBM meta tag.
->coordinatesInGeoTagsMetaTagICBM()
::: code-group
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->coordinatesInGeoTagsMetaTagICBM();
<meta name="ICBM" content="9.945600, -9.696600">
:::
Retrieves the coordinates in geo meta tags format, with placename and region.
->coordinatesInGeoMetaTags($locale = 'en')
::: code-group
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->coordinatesInGeoMetaTags();
<meta name="geo.position" content="-23.442500; -58.443800">
<meta name="geo.placename" content="Paraguay">
<meta name="geo.region" content="Americas">
:::
Retrieves the coordinates in GeoJSON format.
->coordinatesInGeoJSON()
::: code-group
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->coordinatesInGeoJSON();
{
"type": "Point",
"coordinates": [
4.3517,
50.8503
]
}
:::
Retrieves the coordinates in CSV (Comma-Separated Values) format.
->coordinatesInCSV()
::: code-group
use Lwwcas\LaravelCountries\Models\Country;
$country = Country::inRandomOrder()->first();
$country->coordinatesInCSV();
latitude,longitude
15.2,-86.2419
:::
How can I help you explore Laravel packages today?