gamelan
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Linked Data Planet Conference & Expo


Developer Jobs

Be a Commerce Partner
Shop Online
Promotional Products
Hurricane Shutters
Promotional Pens
Send Text Messages
Remote Online Backup
Web Hosting Directory
Condos For Sale
Online Shopping
Dental Insurance
Promotional Golf
Televisions
KVM Switch over IP
Logo Design

 


  Managing the Modern Network
Sponsored by HP
In a global economy where information crosses the globe in an instant, and where Web-based applications power business, it's more important than ever to ensure your network is safe from threats and optimized to deliver the data your business needs. »
 
  Business Service Management: Generate Revenue Through IT
Sponsored by HP
IT must now help organizations attract, retain and grow customer relationships and increase customer satisfaction. Business service management (BSM) helps lay the foundation by managing services in dynamic support of business requirements. Learn more. »
 
  Evaluating Software as a Service for Your Business
Sponsored by Webroot
Is Software as a Service just hype, or is something really going on here? See if your company can benefit as SaaS tries to change the face of the enterprise. »
 
  Storage Networking: Configuration and Planning
Sponsored by HP
The most critical part of setting up a SAN is configuring each individual disk array. This guide examines configurations for SAN-attached servers and disk arrays, and looks at the future of IP storage. »
 
  Is Your Disaster Recovery Plan Good Enough?
Sponsored by HP
Preparing for a disaster is more often than not part of the storage planning process, and it is one of the most difficult tasks, since it includes local hardware and software, networking equipment, and a test plan. Learn how to get disaster recovery right. »
 
Related Article -
Building a Geocoding Web Service
Build Your Own Geocoding Solution with Geo::Coder::US
Retrieving Map Location Coordinates
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Project Management Guide: Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.

Integrating Google Maps into Your Web Applications
By Jason Gilmore

Go to page: 1  2  3  Next  

Sci-fi author Duncan Munro's 1950 short story "U-Turn" includes a well-known passage that reads, "May you live in interesting times." I haven't actually read the story, therefore can't say whether it was meant as a blessing or a curse. Regardless, it seems particularly applicable to those of us steeped in Web development, as the last ten years have truly proved to be a whirlwind of excitement. And as the Web platform continues to mature, we're seeing an increasing number of amazing technologies that will take our applications to new levels of power and usability. The most recent development to catch the eye of developers worldwide is the so-called Ajax model, shorthand for Asynchronous JavaScript + XML. This notion seems to have revitalized the Web development community's goal of creating applications that are as rich and responsive as any desktop-based application, but with the added advantage of accessibility via the ubiquitous web browser.

Perhaps the most famous applications embracing the Ajax model is Google Maps. Surely you've played around with this website, perhaps entering your or other addresses of interest, and marveled as how the site responded to zooming and dragging around on the map in seeming real-time. Wouldn't it be great to incorporate Google's mapping capabilities into your applications, taking advantage of not only its enormous database, but also the eminently cool interface that comes with it?

You might be surprised to know Google offers a free Application Programming Interface (API) that makes doing so pretty trivial. Provided you abide by the Terms of Use, and don't surpass 50,000 page views per day without obtaining prior permission, you're free to use this API to embed Google's mapping technology into your website. In this article you'll learn how to do exactly this. Specifically, you'll learn how to integrate maps into web pages, extend the mapping feature to mark locations of interest to your site users, and even display location-specific descriptors simply by clicking on the corresponding icon. But first, for inspiration take a moment to peruse some of the amazing implementations already popping up across the Web:

  • Chicago Crime: A spatially-enabled database of reported Chicago crime.
  • HousingMaps: HousingMaps.com takes advantage of Craiglist and Google Maps to visually depict houses and apartments for sale and rent across the United States.
  • Recent Earthquakes: Charts earthquakes taking place across the globe over the past seven days.
  • Google Maps Mania: An interesting blog covering Google mapping news and projects.

Prerequisites

No special development tools are required in order to take advantage of Google's mapping API; all that is necessary is a text editor, Web browser, and a public Web server from which the scripts can be served. Note the server must be public, you can't develop on an internal server, as each request must communicate with the Google mapping server in order to work correctly. You will however need an API key provided by Google so that usage quotas can be monitored. Begin by reading through some of the usage rules and applying for the key here:
http://www.google.com/apis/maps/signup.html

You'll need to confirm registration by clicking on link provided by you via email, at which time the API key will be provided to you. Paste this key into a text file, as you'll need to integrate it into the scripts used to create the maps.

Your First Map

Incorporating a Google map into your website is surprisingly easy, accomplished with just a few lines of code. Begin by copying and pasting the following snippet into an HTML file, remembering to replace ADD_YOUR_KEY_HERE with your own API key. Then save and upload the file to a Web server.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 

      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

  <head>

    <script src="http://maps.google.com/maps?file=api&v=1

            &key=ADD_YOUR_KEY_HERE" type="text/javascript">

    </script>

  </head>

  <body>

    <div id="map" style="width: 400px; height: 300px"></div>

    <script type="text/javascript">

    //<![CDATA[

    

    var map = new GMap(document.getElementById("map"));

    map.centerAndZoom(new GPoint(-83.022206, 39.998264), 3);

    

    //]]>

    </script>

  </body>

</html>

Executing this script from a Web server produces the following map of my alma mater, The Ohio State University:

The Ohio State University

There are four key components to this script. The following snippet makes the Google map JavaScript script available for use in your script. Note you'll need to supply the API key discussed in earlier in the article.
<script src="http://maps.google.com/maps?file=api&v=1

&key=ADD_YOUR_KEY_HERE" type="text/javascript">

The next snippet specifies the placeholder for the map, and specifies its dimensions. Note you're able to place this line anywhere on the page, positioning it using tables or CSS as desired:

<div id="map" style="width: 400px; height: 300px"></div>

    <script type="text/javascript">

The next snippet creates a GMap object (instantiated from a class found in Google's JavaScript script), readying it for manipulation and display other methods found in the script:

var map = new GMap(document.getElementById("map"));

Finally, the map is centered and displayed on a location declared by latitude -83.022206 and longitude 39.998264. The second parameter of the GPoint constructor determines the height, with 1 offering the lowest (most detailed) height and 16 offering the highest (least detailed).

map.centerAndZoom(new GPoint(-83.022206, 39.998264), 3);

You might be curious to know how I determined the university's latitude and longitude coordinates. At present, Google doesn't offer a means for converting mailing addresses to zip codes, therefore you'll have to depend on some other service for doing so. Thankfully there are several such services out there, perhaps the most compelling of which is geocoder.us. If you're interested in looking up the coordinates for an occasional address, you can do so via the geocoder.us website in seconds. If you're building a commercial application requiring repeated lookups and would like to leave this process to another party, geocoder.us offers a Web Service at a very competitive price. Or if you'd like to take matters into your own hands and manage the conversion process yourself, geocoder.us actually points you in the right direction by offering information about the Perl module Geo::Coder::US and the freely available U.S. Census Bureau TIGER/Line data.

Go to page: 1  2  3  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Web-based Java Archives

Developing Intelligent Communications? Visit the Avaya DevConnect Center on DevX.
Guide to Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.
Data Sheet: IBM Information Server Blade
Is it time to make your move to the multi-threaded and parallel processing world? Find out!
Five Trends for Application Development. Download Your Complimentary Report. Exclusive. Act Now.



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES