Category: Tips


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.

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.

Let me start off by saying WOW. I have to say, this year’s Facebook F8 Keynote address was absolutely spectacular, from both a geek’s and a regular user’s point of view. Mark Zuckerberg and the guys at Facebook have really been hard at work, and after hearing Mark’s closing words that we can make the world a better place, it is clear that they are truly shooting for the stars with their latest offerings.

In the presentation, the focus was on the concept of the “open graph”. Essentially this is the idea of a user’s individual network which consists of connections and links to people, places, and things. The current structure of Facebook and the network is fairly linear; most users’ updates are seen for a few hours and then fade away into the abyss. Facebook’s goal is to transform the network from a linear, Facebook centric network, to one that is easily ported to any site across the web. The implications and reach of this new paradigm shift will prove to be a monumental change from how Facebook has done things in the past.

The first part of the announcement was regarding new Facebook Social Plugins. These plugins will be built on top of the new Open Graph API (more to follow), but they are built with the idea of simplicity in mind. With the new plugins, developers can now insert a single line of code to provide instant personalization of their website with the user’s social graph. The most important new plugin will be a new “like” button. The new button doesn’t require the user to login or connect to the site anymore; if you are logged in to Facebook, you can simply click the like button on the external website and have that information posted to your profile immediately. For developers, the plugins and new system mean no more having to register an application or maintain API keys, they can simply insert a single line of code and have the functionality go live.

The second part of the announcement was regarding the Open Graph Protocol, and is one of the most crucial parts of the new transformation. The new protocol is a set of meta tags that developers will use on their site to markup a page to tell Facebook what the page represents. In an example, they presented the use of the new tags with IMDB.com. The new tags define what the content is in a way that allows for a more rich and dynamic interface between information. On IMDB.com, a movie page would have tags telling Facebook that the page is about a movie, its name, title, and other information. When a user clicks the like button on a movie page, Facebook knows that it’s a movie and should be put in the “movies” section on the user’s profile. What’s even more cool (from a geeky developers perspective) is that the content displayed on the user’s profile (i.e. the movie name) will link back to the site where the user originally liked the content! This may not seem like much, but this is a truly monumental paradigm shift; previously, everything was about keeping information contained to a Facebook profile page. To paraphrase, the old idea of the web is a bunch of connections that are defined by static links. The future as Zuckerberg and the guys at Facebook see it is that connections are defined more by the social graph, people, places, things, and objects than just static links and information.

The last part of the announcement was about the Open Graph API. Facebook seems to have really listened to developers in this process and shifted their focus to one very clear vision; simplicity. The guys at Facebook, along with some friends from the newly acquired FriendFeed, have completely rebuilt their servers and backend with simplicity, stability, and the Open Graph structure in mind. All of the new Open Graph APIs will be available at http://graph.facebook.com. All a developer needs to implement the APIs is a browser and curl. The idea is that, once given permission, a developer can access any pertinent data about anything on Facebook including people, places, things, etc. via a simple call to (eg: graph.facebook.com/someuser ). What this also means is that developers no longer have to maintain a “Facebook API Codebase”, which has been a huge frustration amongst Facebook App developers. This means developers can write their code once and know that it will always work, and it will be a much simpler, quicker, easier to implement than ever before. The API will also allows developers to search across all public updates from users, a move sure to have the guys at Twitter more than a bit nervous. Another key feature about the API is that it will have real-time updates baked right into the API itself. Developers will now be able to append “callback urls” to their API calls, which will in turn tell Facebook to send updates regarding the specified object to the specified URL. This means that developers will no longer have to “ping [Facebook] server 1000 times a day”, a comment that drew roaring laughter from the crowd who’ve experienced those exact pains. The last part of the API announcement, and probably one of the most groundbreaking aspects of it all, was the announcement that the Facebook authentication system will now be using the OAuth 2.0 standard, joining the likes of Yahoo, Google, and Twitter. The new authentication system will transform the Facebook authentication process from a three day ordeal to a 3 minute breeze.

According to Zuckerberg, “The web is at an important turning point”. Up until now, most websites haven’t been very social and don’t use peoples’ real identities. With the new Open Graph experience, users will be able to transport their real identity with them across websites with ease. With news of this announcement and some help from some launch partners, Facebook is predicting that it’s new Open Graph system will process one billion likes in the next 24 hours. Mark Zuckerberg summed up the goal of the “New Facebook” by saying “the world can be a lot better place, and we can make it that way.” What do you think?

*Editors note: This post is one of many to follow covering the new Facebook goodies. Check back soon for more in depth coverage of the latest offerings from Facebook

Ever wanted to increase your skills but don’t have the $ to go back to college? Check out MIT’s OpenCourseWare – http://bit.ly/axEBzr

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);