Google Maps and PHP

I've kept a map of my travels since around 1999, I used to use the now defunct PARC Xerox Map Viewer, when that went away I started just projecting dots onto XPlanet maps to produce a static map.

Ever since Google introduced their Google Maps system a number of mapping tools became available, dedicated blogs have been written like the very good Google Maps Mania and I've been thinking of trying to do my map using that instead.

Gary got hold of some code which got me going but it was a bit of a PITA so some searching brought me to Google Maps EZ which is basically a javascript library that takes standard HTML HREF's and turns them into points etc, very easy to use.

My problem was still that maintaining data in a html file of HREF's isn't exactly what I had in mind, I was more partial to a XML file like the sample below:

<points>
   <point>
      <lat>-33.9333</lat>
      <long>18.4667</long>
      <type>lived</type>
      <title>Cape Town</title>
      <country>South Africa</country>
      <href>http://flickr.com/photos/ripienaar/tags/capetown/</href>
      <linkimg>images/19591136_35a14f6d58_s.jpg</linkimg>
   </point>
</points>

This contains a lot of information, the type of visit I made to the location, links to my images taken there, a thumbnail to show for the links etc it wouldn't be great to automate the parsing of that to output the HTML for GMapsEZ?

So that is exactly what I wrote. My script takes a simple configuration file like the one below:

[map]
data = visited.xml
type = map
extend = "http://maps.google.com/maps?ll=51.964577,-1.241455&spn=\
      3.460112,7.639893&hl=en"
width = 350
height = 200
showcountry = 1
showtype = 0

[controls]
mapctrl = 1
typectrl = 1
scalectrl = 0
size = small

[types]
visit = orange
transit = blue
lived = green

[misc]
gmapez=http://www.devco.net/visited/gmapez.js
apikey="mykey"

By calling the script I wrote and passing the config file as argument it will produce all the HTML GMapsEZ needs to do its magic.

   <?
      require_once("gmap.inc.php");
      print(getGMapEZ("smalldemo.cfg"));
   ?>

And this is the map it will produce, this is just a screenshot of the final result, see below the image for a link to the full working page.

My full working version of the map can be seen here, it's the same data as above just a much bigger map, bigger controls and a different extend. The only actual difference are some changes to the config file, same data and same PHP code was used.

I've set up a Wiki to maintain documentation for this as it matures over time, I will make announcements of new features on this blog, but the Wiki will be the resource that contains a always up to date reference to features and installation. You can read about obtaining, configuring and using this script there.

4 Comments

cool, thanks.

What an excellent PHP Google Maps implementation. I've been playing around with Phoogle Maps at http://www.system7designs.com/codebase but that isn't that well maintained. I may have to order something on your wishlist if I get time.

Great work.

Have you considered adding the Google geocoding API into this? Is some great code but that would make it bullet proof.

Hi,

Can we use google maps dynamically but without logitude and latitude?

Thanks in advance.
Source: http://myzonal.com

Leave a comment

Recent Entries

  • Load Balancing with HAProxy

    Load Balancers are some of the most expensive bits of equipment small to medium size sites are likely to buy, even more expensive than database...

  • SixXS IPv6 and CentOS

    I thought its high time I get to spend some time with IPv6 so I signed up for a static tunnel from sixxs.net, apart from...

  • Location aware Bind for RedHat 5.3

    Previously I wrote about RPMs I built to GeoIP enable Bind using the original patches at http://www.caraytech.com/geodns/.I have now refreshed this for the latest CentOS...

  • CentOS 5.3

    CentOS 5.3 was released on the 1st of April, I've since updated a whole lot of my machines to this version and been very happy.There...

  • WIRED UK

    I was quite excited about the new UK edition Wired.  I'm not anymore.I got my first exposure to the Wired while in school in South...

Close