Linking to a place at Google Maps in PHP

Posted June 19th, 2020

In a recent project I needed to link to a specific location at Google Maps. Google Maps offers a real simple syntax to link to a predefined location at google maps. For example, this is a link to the Elbphilharmonie Hamburg: http://maps.google.com/maps?q=Elbphilharmonie%20Hamburg

Manually creating the URL every time I need to link to a map is cumbersome and not very object oriented, so I've created a PHP package to handle this for me. While there are excellent packages to communicate with all Google Maps APIs, I couldn't find one that just creates these links, nothing else.

Here is a litte snipped that generates me the above link:

$gMapsLocation = new pschocke\GoogleMapsLinks\GMapsLocation();
echo $gMapsLocation->location('Elbphilharmonie Hamburg');

You can also generate a maps-link based of coordinates:

$gMapsLocation = new pschocke\GoogleMapsLinks\GMapsLocation();
echo $gMapsLocation->coordinates('53.541321', '9.983945');

In the near future, I plan to also integrate the directions API and create a wrapper for Laravel, so the package can take advantage of Laravel blade directives.

You can find the package at my Github: pschocke/google-maps-links