https://github.com/ministryofweb/php-osm-tiles
A library which converts geographical coordinates to map tile numbers
https://github.com/ministryofweb/php-osm-tiles
conversion coordinates openstreetmap osm tiles
Last synced: about 1 year ago
JSON representation
A library which converts geographical coordinates to map tile numbers
- Host: GitHub
- URL: https://github.com/ministryofweb/php-osm-tiles
- Owner: ministryofweb
- License: mit
- Created: 2018-01-30T12:07:09.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2023-12-04T14:15:10.000Z (over 2 years ago)
- Last Synced: 2025-04-07T09:13:58.556Z (about 1 year ago)
- Topics: conversion, coordinates, openstreetmap, osm, tiles
- Language: PHP
- Size: 29.3 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP OSM Tiles
This library helps to convert OpenStreetMap (OSM) map tile numbers to
geographical coordinates and vice versa.
[](https://github.com/ministryofweb/php-osm-tiles/actions/workflows/php.yml)
## Installation
Using Composer, just add it to your `composer.json` by running:
```shell
composer require ministryofweb/php-osm-tiles
```
## Compatibility
The PHP OSM Tiles library requires PHP >= 8.1.
If support for older PHP versions is needed, the PHP OSM Tiles library can be installed at version 2.0 (PHP 7.3, PHP 7.4 and PHP 8.0), 1.0 (PHP 7.1 and PHP 7.2) or version 0.1.0 (PHP 7.0).
## Usage/Examples
## Convert from geographical coordinates to map tile numbers
```php
toTile($point, $zoom);
printf('/tiles/%d/%d/%d.png', $zoom, $tile->x, $tile->y);
```
The code above produces the output below:
```text
/tiles/13/4400/2687.png
```
## Convert from map tile numbers to geographical coordinates
```php
toLatLng($tile);
printf('%.5f, %.5f', $point->lat, $point->lat);
```
The code above produces the output below:
```text
52.50953, 13.35938
```
## Get Bounds of a Tile
It's possible to get the coordinates for the Tiles north-western, north-eastern, south-eastern and south-western nodes:
```php
lat . ', ' . TileBounds::getSouthEast($tile)->lng . PHP_EOL;
```
The code above produces the output below:
```
South-eastern point for tile is located at: 52.496159531097, 13.51318359375
```
## Run Tests
``` shell script
make test
```
or
``` shell script
./vendor/bin/phpunit
```
## Run all CI tools
``` shell script
make ci
```
## OpenStreetMap Map Tile Names Documentation
- https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames