Tag Archive: PHP


Google has just announced Street View support for the Google Maps API v3! I have already taken the liberty of implementing a quick method on the PHPGoogleMapAPI class (called enable/disableStreetViewControls() ). Check out the demo or head on over to Google to read more details on the announcement.

(Special thanks to GoogleMapsMania blog for details on how to implement before the docs were even released – kudos!)

Just finished adding some new features to the PHPGoogleMapAPI Class.

My First and foremost favorite is the ability to add an elevation chart to a page for a related polyline on a map. See the example below:

I’ve also added the ability to switch between the “horizontal” and “dropdown menu” style of Map Type controls. See the demo here.

I was updating some stuff for the PHPGoogleMapAPI today when I came across a new message on the Google Maps API reference page: “New! Layers within the V3 Maps API, including layers to display KML, Bike paths, and Traffic information.”

As such, I have added 2/3 of the new features to the PHP Google Map API Class (traffic and biking overlays), and am hard at work implementing the KML/GeoRSS Overlay features into the class.

Thank you Google – you guys are a lifesaver. Can’t wait for the next goodies that you’re coming out with (**Might I suggest Google Earth overlay integration, tabbed info windows, GoogleBar, Adsense Ads, and overview map control integration?**). Head on over to http://code.google.com/p/php-google-map-api to grab the latest version of the PHP code to integrate into your project today.

It’s the year 2010 and o’ the times they are a changin’. I’ve been using an old PHP Class for Google Maps from Monte Ohrt for a few years now. The class was very well written, and was easy to integrate across a number of projects. The speed at which this library enabled me to develop applications was invaluable during implementation. I’ve grown a certain fondness for the class after the years, and that fondness is what brings me to this point today.

With Google Maps constantly tinkering with and updating their APIs, updates to the library haven’t particularly gone hand-in-hand. To be frank, the library is horribly out of date with the latest offerings from the Google Maps API. As time passed, I slowly added on pieces here and there to suit my needs for the latest project, but never really did them in a way that was “good for the library” so to speak. With the newest version of the Google Maps API (v3), a lot has changed, and I’ve been procrastinating on updating the inner workings to align with the latest offerings.

With that said, I am proud to announce the release of PHPGoogleMapAPI (3.0beta)! Technically, I’m versioning this release as a “beta” since some of the core functionality was re-written/re-factored, so I don’t want to confuse anyone/break anything that might have relied heavily on the deprecated functions (for those who are interested, I’ve deprecated the use of addMarkerIcon in favor of addIcon + updateMarkerIconKey ). Re-writing the library to make use of V3 of the Google Maps API proved to be an epic battle between legacy features, legacy (but updated) API functionality, and whole new paradigms on how things are done in v3. More than a few of the updates that I diligently scrubbed, globalized, and OO’ized (yes I made that up) that I tried to implement at the new v3 Google Maps API level are sadly missing from the new API. This includes stuff like adding a Google Local search bar, Google Adsense Ads (both on the map and in Local search results), Google Earth map overlays, and traffic overlays, to name just a few. These features just simply aren’t available from the API, and I sadly had to remove them from the library (don’t despair just yet, I just commented them out to make it easier to re-implement them once the API comes back around).

Even with all that it’s missing, this latest version is pretty powerful, and I hope that it helps more than a few developers like myself who’ve struggled with staying up to date with the latest offerings from the Google Maps team. By no means do I consider this project to be near completion; in fact I’ve probably jumped the gun and released the “beta” too early and will hear mean feedback from early adopters finding some stuff hasn’t been ported yet. Not to fear; I’m hard at work in the “Brad’s Labs”, or Brabs, tweaking the inner workings to make sure that this latest breath of fresh air into the project can give it a new set of wings.

In working on a few of my projects, I had a few issues dealing with extremely large XML files. More specifically, every computer that I tried to open them on failed miserably. I did a lot of searching and scouring of the internet to find a program that did this automatically. The best program I could find was called “Large Text File Viewer”, and that’s far from what I was looking for, although I was still happy to find a program that I could use to even just simply open the large files.

I started to try and “chunk” the files myself by hand, and after creating a few files thought to myself “there has to be an easier way to do this”. I got back on and kept searching for a solution. After a lot more digging, I finally came across a simple script doing exactly what I wanted it to do. I took the script and modified it a bit to follow OOP standards a bit more (before all addresses, URLS, etc. were hard coded).

Here is the class that I ended up creating:

class xmlChunk
{
function xmlChunk(){
}
/*$basefilename // the base file name for the chunks
$xmlfile // the xml file name to be processed
$xmldatadelimiter // core data delimiter
$xmlitemdelimiter // record delimiter
$chunksize = 2000; // number of records in each chunk file
$dir // path to where splits will be stored
*/
function doChunk( $basefilename, $xmlfile, $xmldatadelimiter, $xmlitemdelimiter, $chunksize=2000, $dir= "/var/www/public_html"){
//initialize vars
$begin=time(); // script start time
$start = time(); // last gate time
$interval=time(); // current gate time
$minutes=1; // intervals for gates
$filenum = 1; // start chunk file number at 1
$recordnum = 1; // start at record 1

$xmlstring =''."\n";
$xmlstring.="<$xmldatadelimiter>\n";
// xmlchunk file header
//dirs and files

$exportfile = "$dir"."/splits/$basefilename-$filenum.xml";

//start processing
echo "Processing (".$dir."/$xmlfile)\n";

$handle = @fopen($dir."/$xmlfile","r");

if ($handle) {

while (!feof($handle)) {

$buffer = fgets($handle, 4096);
// if item delimiter reached
// increment record number iterator
if (ereg("",$buffer)==true) {
$recordnum++;
}
//write line to chunk file
error_log("$buffer",3,$exportfile);
// if chunk limit reached then start to
// close the file with well formed xml
if ($recordnum>$chunksize) {

// post feed end tag
error_log("",3,$exportfile);

// and increment file number to start new log file chunk
//reset record counter number for new chunk file
$recordnum=0;
$filenum++;

//update export file name
$exportfile = "$dir"."/splits/$basefilename-$filenum.xml";

//echo status report to STDOUT
echo"Segment $filenum. Record ".($chunksize*$filenum).".\n";

// write new chunk xml file header
error_log($xmlstring,3,$exportfile);
}
//put in a catch so that script doesn't run riot and
//will die after X number of cycles
if ($filenum>5000) {
die();
}

if (($interval-$start)>60) {
$minutes++;
echo $minutes." Minutes so far.\n";
$start=time();
} else {
$interval = time();
}
}
fclose($handle);
} else {
echo"Unable to open file! (".$dir."$xmlfile\")\n";
}
$procend = time();

echo "\n####\n";
echo "Split Complete (".floor((($procend-$begin)/60))." Minutes)\n";
}

}

So, in order to utilize this class, just create a script that calls the previous class file as follows:

require('xml_chunk.class.php');
$basefilename = "filenameChunked";
$filename = "/path/to/xmlfile/file.xml";
echo "Creating ".$basefilename." Splits
";
$chunk = new xmlChunk();

$chunk -> doChunk( $basefilename, $filename,' baseXMLtag', 'itemXMLtag',2000/*limit*/, "/path/to/directory" /*directory must contain folder named "splits"*/);
unset($chunk);