PHP Classes

ah Map Helper: Parse URLs of map services and get their location

Recommend this page to a friend!
  Info   View files Example   Demos   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 164 All time: 8,839 This week: 326Up
Version License PHP version Categories
ah-map-helper 1.0GNU General Publi...5PHP 5, Geography, Parsers
Description Author

This class can parse URLs of map services and get their location.

It can take URLs of maps from Google Maps, Yandex and Open Street map and extract the location coordinates and other parameters.

The class can also regenerate the URLs of map pages of any the supported services given the location coordinates and zoom level.

Innovation Award
PHP Programming Innovation award nominee
May 2016
Number 14
There are several types of mapping applications on the Web that can show specific locations given a URL that represents that location. However, each application uses different URL parameters to represent the location coordinates.

This class provides a general solution to extract location coordinates from map URLs of Google Maps, Yandex maps and OpenStreetMap.

It can also also do the opposite, i.e. given the coordinates of a location it can generate URLs to show that location in the different mapping sites that it supports.

Manuel Lemos
Picture of Axel Hahn
  Performance   Level  
Name: Axel Hahn <contact>
Classes: 5 packages by
Country: Switzerland Switzerland
Age: 50
All time rank: 270526 in Switzerland Switzerland
Week rank: 506 Up3 in Switzerland Switzerland Up
Innovation award
Innovation award
Nominee: 2x



map position helper (Php class)
This helper class can parse urls of a map services Google maps, Openstreetmap 
and Yandex. It fetches the position longitude and latitude from an url.

It generates urls with the same position with other map services.

Licence GPL 3.0

author: Axel Hahn

see DEMO



2016-04-17  1.0  first public release
2016-05-25  1.1  added options minzoom; new methods getUrls() + fixPosition()
2017-01-15  1.2  added  support for regional maps (provider map1eu)



require_once 'ahmaphelper.class.php';
$oMaphelper = new ahmaphelper();

get a position from url:
go to a map provider:
Zoom in, go to any position and copy the url

$aPos = $oMaphelper->getPos($sUrl);

generate urls with the same position

fix position data to be compatible to all map providers. 

manually generate links with position data and zoom level (returns an array):
print_r($oMaphelper->generateUrls($aPos['lat'], $aPos['lon'], $aPos['zoom']));

manually generate link with position data and zoom level to a given provider 
(returns a string):
echo $oMaphelper->generateUrl([provider], $aPos['lat'], $aPos['lon'], $aPos['zoom']);
echo $oMaphelper->generateUrls("google", $aPos['lat'], $aPos['lon'], $aPos['zoom']);

helper functions:

  generate url with the same position to a specific provider
  ... returns names of known providers

  ... returns lowest maxzoom level of all providers

  demo maphelperExternal page  

Open in a separate window

  Files folder image Files  
File Role Description
Plain text file ahmaphelper.class.php Class Class source
Accessible without login Plain text file ahmaphelper.maps.php Aux. Auxiliary script
Accessible without login Plain text file demo.php Example Example script
Accessible without login Plain text file readme.txt Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:8,839
This week:326Up
For more information send a message to info at phpclasses dot org.