Chapter 10. Fun Stuff

Hacks 95–100: Introduction

PHP coding isn’t always about writing accounting applications. This chapter contains hacks that cover the fun side of PHP. From creating your own Google maps, to building an MP3 server, to uploading Wikipedia to your PlayStation Portable (PSP), this chapter’s all about the frivolous side of PHP.

Create Custom Google Maps

Use the Google Maps API to embed dynamic maps into your application with custom markup, overlays, and interactivity.

In what little spare time I have, I love to hike around my neighborhood in Fremont, California. Thankfully, some of the best hiking in the Bay Area is just a walk away. In particular, the hike up Mission Peak is tremendous, both for its scenic vista and for the great workout.

To illustrate my hikes up Mission Peak, I’ve always used a wiki page with a bunch of images. But I always wanted something more interactive—and with the advent of Google Maps and its extensible API, I was able to use a combination of PHP and JavaScript to detail my hike up the mountain, using satellite imagery and interactive markers (how’s that for technology and nature converging!).

The Code

Start by saving the code in Example 10-1 as index.php.

Example 10-1. Setting up latitude and longitude for Google mapping tasks
<?php $images = array( array( 'lat' => -121.9033, 'lon' => 37.5029, 'img' => "mp0.jpg" ), array( 'lat' => -121.8949, 'lon' => 37.5050, 'img' => "mp1.jpg" ), array( 'lat' => -121.8889, 'lon' => 37.5060, 'img' => "mp2.jpg" ...

Get PHP Hacks now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.