Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

Beginning Google Maps Applications with PHP and Ajax

Posted by samzenpus on Mon Aug 28, 2006 12:38 PM
from the map-it-out dept.
Michael J. Ross writes "Just as PHP and other Web scripting languages have made it possible to create dynamic Web pages, online mapping services are making it possible to create dynamic maps that can be customized by a Web site owner, or made customizable by a site visitor. In the case of Google Maps, this is done using the built-in application programming interface (API), which is described in a new book, Beginning Google Maps Applications with PHP and Ajax: From Novice to Professional." Read on for the rest of Michael's review.


But first, a brief background: During the mid-1990s, the only generally available mapping applications were desktop programs with location data limited to major cities within the United States. Yet less than one decade later, those programs were obsolete, replaced by Web-based mapping services such as MapBlast, MapQuest, and Yahoo Maps. In early 2005, Google raised the bar, with its own Web-based mapping service that was far more attractive than the others. For countless Internet users, it was their first glimpse of the power of AJAX, a new combination of technologies that allows Web pages to be refreshed asynchronously, providing a faster user interface. But Google Maps later packed another feature, an API that allows Web developers to leverage the service's capabilities in previously unimagined ways.

The authors of Beginning Google Maps Applications with PHP and Ajax — Michael Purvis, Jeffrey Sambells, and Cameron Turner — are based in Waterloo, Ontario, Canada. The book was published in August of 2006, by Apress, under the ISBN of 1590597079. The publisher maintains a Web page devoted to the title, where visitors can find an online table of contents, a sample chapter (Chapter 3, "Interacting with the User and the Server") as a PDF file, and a link for submitting errata (none of which, as of this writing, appear to have been reported — assuming there are any). In addition, the authors have a Web site for the book, where they offer a sample chapter (Chapter 4, "Geocoding Addresses") in PDF format, links to raw data sources, and brief entries describing a variety of related topics, including geocoding services, Google Maps Mobile (GMM), Keyhole Markup Language (KML), and building your own geocoding using Perl.

The book's material is organized into 11 chapters, grouped into three parts. The fourth and final part contains the appendices. The three primary parts can roughly be thought of as presenting the beginning, intermediate, and advanced information. Part 1, "Your First Google Maps," whets the reader's appetite by showing how to easily create some simple maps (discussed below). In addition, it contains a chapter explaining how a Google Maps mashup interacts with the user as well as the server. The final chapter in this part discusses geocoding addresses. Part 2, "Beyond the Basics," explains how to work with third-party data, how to enhance the user interface, how to optimize and scale for large data sets, and finally what possible future directions Google may take with this API. Part 3, "Advanced Map Features and Methods," presents exactly that, covering such topics as creating custom controls and info windows, adding geometric shapes to maps, and getting the most out of geocoding, including how to work with postal codes.

The authors begin Part 1 ("Your First Google Maps") by introducing Google Maps with the two most simple examples possible: Keyhole Markup Language (KML) is an XML-like formatting language that allows one to specify the names, coordinates, and descriptions of one or more locations ("placemarks") in a single file. For anyone who wishes to avoid writing the code themselves, Wayfaring is a Web site that allows one to create and share custom Google Maps by point and click. Even though the introduction to KML is properly brief, instead of only stating that the sample coordinates were discovered manually, the authors should mention at least one simple way to find those coordinates (such as the "Link to this page" link in Satellite view in Google Maps). Nonetheless, it was wise of the authors to use simple examples to get the reader's feet wet as quickly as possible — especially for prospective readers who might skim through the rest of the book and become intimidated by the technical diagrams, JavaScript and PHP code, MySQL queries, XML markup, and mathematical formulas.

There is much to like about this book. The explanations are straightforward, the code is readable, the examples are relevant, and the writing style is approachable. The illustrations, all of which are in black and white, are well-chosen, and not overwhelming in number. In addition to showing the expected results of the sample code, they also provide enough visual incentive to encourage the reader to give the sample code a try, and perhaps develop it further into their own mapping applications.

The book is not too lengthy, clocking in at 384 pages according to the publisher (though, oddly, Amazon.com reports only 350 pages, even though the last page of the appendix reads "358"). The authors resisted the increasingly common temptation to pad the book with superfluous appendices. Instead there are only two. The first explains how and where to find location data, such as addresses and latitude/longitude points. The second appendix presents the details of all of the classes, methods, properties, constants and events defined within the Google Maps API. For some reason the authors mention "objects" instead of properties and events, but I was unable to find any pre-instantiated objects mentioned in that appendix., and I am not sure such are even possible in the API.

Fortunately, the weakest section of the book, its foreword, has the least impact upon the value of the book. It fails to perform the most basic functions of a foreword, such as explaining to prospective readers why they should become actual readers, as well as what the book covers, and how the authors are qualified to provide that coverage. Instead, its author mostly discusses his personal Google Maps Mania site, and even wedges in mention of his appearance on an NPR radio show, which has little to do with the book. He also lists his first five posts to his Mania site, the first of which contains a misspelling, which should have been caught by the book's editors, or at least indicated with a "[sic]." The best part of the foreword is the first few paragraphs, which provide a brief history of Google Maps and the hacking thereof.

Like most if not all of its titles, Apress helpfully starts this book with two versions of the table of contents — the first one serving as a high-level overview, and the second providing far more detail, listing not only sections but subsections. This is a nice touch, and should be employed by all technical publishers. On the other hand, this book does not have a lay-flat binding, which is a shame, as it makes it far more difficult to read the book with both hands free for keyboarding. With the introduction of lay-flat bindings years ago, it is inconceivable to me why it has not been universally adopted, particularly by technical publishers.

Overall, Beginning Google Maps Applications with PHP and Ajax is an excellent introduction to extending the power of Google Maps on the Web, and provides enough detail to both help and entice readers to build their own Google Maps mashups.

Michael J. Ross is a freelance writer, computer consultant, and the editor of the free newsletter of PristinePlanet.com."


You can purchase Beginning Google Maps Applications with PHP and Ajax: From Novice to Professional from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
+ -
story
This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More
Loading... please wait.
  • by rhizome (115711) on Monday August 28 2006, @12:42PM (#15995018) Homepage
    There's a whole book for this?

    • I'm glad that they have a book for this. How many Google Maps mashups have you made if any? They are not as easy as you think.


      In other news, the reviewer wrote the best definition of the AJAX technology:

      AJAX, a new combination of technologies that allows Web pages to be refreshed asynchronously, providing a faster user interface.
      • Re: (Score:1, Redundant)

        How many Google Maps mashups have you made if any? They are not as easy as you think.

        Well aren't we aggressive today. In fact I am working on a "Where to refill your bike's water bottle in San Francisco" mashup as I type. I haven't found that I need 11 chapters to get as far as I have.

        But then again, you already know how easy I think they are so I'll probably not get very far anyway, since I obviously think they're easy and I am obviously mistaken, dick.

        AJAX, a new combination of technologies that allows We
      • Re: (Score:2, Interesting)

        1

        And yes, it's quite easy for anyone with a education in CS I'd say. If you can read a manual you can implement google maps.
      • I've done a couple, with only Google's docs to guide me.

        Dude, they are easy. Much easier than I expected them to be.

        If Google didnt charge so much for the commercial licence, there would be an explosion of these apps.

    • Re: (Score:2, Insightful)

      According to TFR, yes! A friend of mine did a bunch of google maps API stuff to interface with his GPS system. He goes on bike rides around Arizona, saving the path he took. When he gets home, he downloads the GPS coordinates and makes a route which he can display on his webpage with google maps. I'm sure it can be used for far more advanced things. I bet he could make some really crazy stuff if he read this book.
    • Re: (Score:2, Insightful)

      There's a whole book for this?

      Maybe the first 300 pages or so are simply the search results for "google maps api" [google.com]

      • Re: (Score:3, Insightful)

        Having read a copy myself, the content is centered around the most commonly asked questions on the newsgroup. It takes the common pitfalls (misunderstanding AJAX, too much data, poor navigation, need for custom controls etc) and works them into a cohesive path that guides the reader forwards.

        Basic maps are indeed simple and are covered in depth in the first 3 chapters, but this book goes on to cover dealing with hundreds of thousands of data points where the plain API chokes before 200.

        Sure, much of this ma
      • Tons and tons of major corporate websites are powered by PHP. Lots of other things are too; just as a random example, spreadfirefox is done with drupal, a FoSS CMS based on PHP. That doesn't mean it's the best tool for the job, but in the extremely-rapid-development arena, you don't have very many options. While it is more powerful, java+jsp is more involved than mod_perl, mod_php, ASP, et cetera, and if you want rapid development and more to the point rapid modifications after development, PHP is not a bad
  • good mapping sites (Score:4, Informative)

    by legoburner (702695) on Monday August 28 2006, @12:52PM (#15995087) Homepage Journal
    So what are some of the better mashups out there? The sex offenders one [mapsexoffenders.com] and the gas prices one [mywikimap.com] are both quite cool. What other decent ones are there?
  • WHO cares ? (Score:5, Insightful)

    by unity100 (970058) on Monday August 28 2006, @12:55PM (#15995117) Homepage Journal
    There are very small number of people and businesses who are able to put forward such capitals that might dwell on ajax apps, and dependencies on third party sources like google and try to establish a youtubeish, or some other service. (youtube is given as an example to imply a big operation)

    Almost 80% of the web development market is comprised of small businesses or individual investors, who do not care the slightest for ajax widgets, mumbo jumbo or the such when they start an online presence. Their problem is, selling their wares, or services via a secure, easy and clock-like working site.

    Much hype was done around this ajax, yet we as web developers still are not seeing any demands on ajax stuff in contracts. And the ones that there are negligible when proportioned to the whole.

    Im increasingly starting to see this ajax thing as a new "techno trend" that is pumped up and put forth by genius-tech-wizz kids (net celebrities) who did big business with similar things in the past.

    The catch is, market does not need it.
    • Re:WHO cares ? (Score:4, Informative)

      by truthsearch (249536) on Monday August 28 2006, @01:16PM (#15995244) Homepage Journal
      My company is getting a lot of requests for AJAX or similar features, especially as it relates to letting users customize a page design by dragging around components. AJAX itself is never an exact requirement, but we are often getting asked to add features which require some robust javascript.
    • Re:WHO cares ? (Score:5, Insightful)

      by Mateo_LeFou (859634) on Monday August 28 2006, @02:59PM (#15995921) Homepage
      I think you'll see Tons of requests for AJAX as it continues to soak in. I just did a draft page for a new client. Front page had three links -- two of these used AJAX and the other used ye olde http redirect. Took all of 5 seconds for client to say "you'll fix that one so it works like the others, right?"
    • Re:WHO cares ? (Score:4, Insightful)

      by cyngus (753668) on Monday August 28 2006, @03:23PM (#15996054)
      If you think that AJAX is just some catch-phrase or piece of eye canding, then I think you misunderstand a lot of human interface principals. The Click-Submit-Reload pattern that is required without something like AJAX is very disruptive to the user experience. AJAX can eliminate this cycle to produce a much more fluid experience. AJAX can be over-used or used badly, but when used correctly, is much more than just some cool toy.
    • I do. (Score:3, Interesting)

      You're just working on the wrong kinds of apps, apps where "AJAX" is just a parlor trick to show that you're a really hip developer.

      There are many applications that are just fine as "web applications". Blogs for example. Most shopping cart type applications. There may be an occasional place where sprinkling a bit of ajax fairy dust makes the application a bit nicer (altough often less nice if you are vision impaired).

      There are other applications that suck as "web applications". They are now what we used
      • That is indeed my point - there are very small amount of investors who can even think of entering enterprises that would use or need GIS systems, or NASA World Wind or the like.

        Considering it is the small to medium businesses, and individuals who are fueling the internet in its majority, and very big companies like google, aol or the like having their own development teams, that only leaves a small fraction of medium to big capita to ever think of sailing such seas, and natually a fraction of it would be
        • That is indeed my point - there are very small amount of investors who can even think of entering enterprises that would use or need GIS systems, or NASA World Wind or the like

          World Wind is a bad example. Ironically, the standard "store finder" application for your large company doesn't really require GIS either.

          But, there are actually a large number of organizations ranging from small to large that can use geographic applications. They are, as you say, a niche, but that doesn't mean that the niche is sm
          • Well, thats another issue - there are many businesses that can make use of geographical solutions, but the are unaware of it. In fact, there are many technologies that many businesses can use, but all are unaware of them too.

            The catch is, most will continue to be unaware, and noone is going to make a campaign to make them aware, and many of the ones that became unaware could be uninterested.

            • The catch is, most will continue to be unaware, and noone is going to make a campaign to make them aware, and many of the ones that became unaware could be uninterested.


              OT, but did you go to the same school as Don Rumsfeld ;-)
    • Re: (Score:3, Interesting)

      Speak for yourself. There are a couple ways to tackle this obviously highly biased diatribe that has very little basis in reality.

      On the one side is the financial take. Assuming your numbers are correct, how much money is behind the 20% of 'big business' sites do you think?

      Are you truly suggesting that rich web applications are something that doesn't make these companies money?

      Is it impossible for widgets and templates to be wrapped up in a nice customizable package and sold to smaller businesses for very a
      • There are very small amount of investors who can even think of entering enterprises that would use or need GIS systems, or NASA World Wind or the like. Considering it is the small to medium businesses, and individuals who are fueling the internet in its majority, and very big companies like google, aol or the like having their own development teams, that only leaves a small fraction of medium to big capita to ever think of sailing such seas, and natually a fraction of it would be interested in doing stuff
      • The problem is, the contract owner requests so extravagant and absurd changes to the software in new contracts for developing the previously produced work that ajax is prone to become a major factor in hampering the new changes. As you know, until they are explained in detail, the contract owners are, naturally being unaware of the software nature, can request a simple looking change and be totally unaware of what massive work it would require.
      • Many anti-virus, firewall and privacy software create problems with javascripts and activex anyways.

        It is much better to altogether let go of javascript and activex.
        • Do you still run Windows 3.1 on a 486?

          Do you still drive a ford Pinto?

          And of course, well designed web applications will degrade gracefully, just for you few stragglers that refuse to allow the internet to be anything more than a text reader. Well, actually, not for you. But for the few that have _legitimate_ reasons.

          BTW, low bandwidth is NOT a good reason to diss things like AJAX. Case in point, I recently upgraded one of our core web features that almost all of our low bandwidth customers were having prob
          • Already security software, including anti-virus, firewalls, privacy software are blocking and creating problems for many java applications and activex procedures.

            Leaving that aside, you are wrong in your point. Bandwidth is now much more important than it has ever been, because of the disgusting laws that the at&t and other telcos are pushing.
            • java and activex yes, that's a different conversation entirely.

              As for bandwidth, I was stating that proper use of AJAX can REDUCE bandwidth useage, sheesh.
  • by Frosty Piss (770223) on Monday August 28 2006, @01:00PM (#15995158)
    The main problem I have with the Google Maps API is that the dataset that they let non-paying users use for Geocoding (extracting the Lat/Lon from an address) is not accurate. Yahoo provides Geocoding with much much better accuracy. So, if you need accurate Lat / Lon data, you'll have to fold both mapping technologies into your app (get the lat / lon of an address from Yahoo, plot on a map with Google. Or just use Yahoo and skip Google).
    • Actually, keep an eye on the book's blog; in the coming weeks, we'll be publishing a tool to help you compare the various free geocoders.
    • Or... You could download the Tiger/Lines Data from the Government and do it yourself with Perl then feed the long/lat to Google instead of using their geocoding API. Just the maps!

      http://search.cpan.org/~sderle/Geo-Coder-US-1.00/U S.pm [cpan.org]

      It rocks. I've been using it with my voter lists for Door to door.

    • I've had good luck with Yahoo's geocoding services. At the time I mucked with this stuff, Google had not yet put up their geocoding service.

      The big problem I have with Google maps is the API uses TeleAtlas in my area which is verging on 10 years out of date, but going to maps.google.com, my area is using NAVTEQ data, which is fairly current. It's possibly a licensing issue, but it's damned annoying to have whole major highways missing in my app.

      Your mileage, of course, may vary.

  • by elyobelyob (844203) on Monday August 28 2006, @01:35PM (#15995378)
    Google maps API is still very much in development with new features coming out all the time. When they switched from v1 to v2, there was a lot of converting to be done to make maps work correctly. This book will be out of date in no time. Can't see the need for it when you have an active mailing list and sites such as mapki available.
    • Re: (Score:2, Informative)

      It's true there are new features all of the time, but with version 2 of the API Google has stabilized the core of the system. Moreover, the authors acknowledge this "moving target" and have set up a dedicated site to act as an ongoing companion. If what I've seen so far is any indication they are dedicated to keeping all their readers up to date.

      http://googlemapsbook.com/ [googlemapsbook.com] if you're interested.
  • by Corporate Gadfly (227676) on Monday August 28 2006, @02:09PM (#15995621)
    I find Mapki [mapki.com] and Mike William's Tutorials [demon.co.uk] more than sufficient. A quick glance at the API group's mailing list [google.com] also helps.
  • Those interesting in the topics should take a look at the Google Maps Hack book (review here [slashgeo.org]).

    Anyone whom have interest in Google Maps API must take a look at the numerous alternatives. Which includes OpenLayers.org [openlayers.org] (which just released v2.0 [narx.net]). There are various other alternatives, all with different levels of interoperability and compatibility with OGC standards [opengeospatial.org]. On the subject, see slashgeo's web mapping section [slashgeo.org].
    .
  • Have a client, a chain of national francised outlets that wanted to use this technology for a branch locator. We were all set to build this with the .NET APIs that Google provides, but when the client caught wind of the licence charge for commercial entities, the project was canned. I fear that this very cool solution is going to remain limited by what Google is asking for licencing.

    Sure, they have the right to charge whatever they want, but damm, who is going to adopt it at that rate just to add some coo

    • Is this fee required? I thought that it was only if you wanted to have dedicated servers so your commercial app doesn't have to compete with the rabble for the limited google maps bandwidth.

      The laternative might be to use Yahoo Maps' new API. I haven't played with it much yet, because I don't want to install any plugins to use it. But lots of folks probably will. This book would be better if it was more even-handed and presented info on yahoo as well.

      Still, I'll probably buy it. But not on dead tree, but wh
    • The fee is most definitely not required for this specific application. Your client could have used the technology for a branch locator with no problem -- it has been done numerous times before and there are plenty of tutorials [google.com] on how to do it.

      The fee is required for sites that want to do more than 50,000 hits a day (to the map server) or want to put the map somewhere that is not publicly accessible (as the current API requires).

      Ian (from http://mapki.com/ [mapki.com]
      • Thanks for the info, maybe the Google docs that come with the APIs could have been better worded? Or maybe I'm just clueless? Dont answer that.
  • Has anyone checked out "Ajax And Php: Building Responsive Web Applications (Paperback)" [amazon.com] If I can only afford one of these books, should I get this one or the one reviewed here on /.
    • Did you REALLY just ask that question?

      OK, I'll make it _real_ simple for you, one question is all I need answered:

      Are you interested in learning mapping using google maps API, or are you interested in learning AJAX with PHP?

      Given the answer to that question, I sure do hope you can figure out the rest on your own. If not, I highly suggest neither.
    • You heard the man! Let's get cracking on WebForth immediately! Imagine... all the interactive capabilities of the web combined with the ease of programming of Forth! What could be better?
    • Virtual Earth isn't as nice to use as Google Maps, and certainly Google Earth. The birds eye view is excellent, but it's just pictures, not an interactive globe.