|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
TOP COLDFUSION LINKS CF Techniques An In-Depth Look at Mapping APIs
The benefits and drawbacks
By: Joe Danziger
Apr. 20, 2006 04:00 PM
Back in the November 2005 issue of CFDJ, we looked at how to create a live map of your Web site visitors using Google Maps and other freely available services. Now that Yahoo! and Microsoft have joined the fray and released their own mapping APIs, we'll revisit our example while learning about each implementation along the way. All of these APIs are extremely powerful, but each has its own advantages that may work better for your particular solution. We'll take a look at each in detail and outline some of the benefits and drawbacks of each.
We'll set up a table (see Listing 1) to keep a log of user visits. Each time a new user visits the site, we'll query the geolocation database and insert a record of the user's IP address, latitude, longitude, city, state, country. In CFMX 7, this code can be put inside the onSessionStart() function in Application.cfc. Queries are executed via HTTP against the NetGeo database by calling the URL http://netgeo.caida.org/perl/netgeo.cgi?target=64.19.164.74. It will return the following data to the browser:
VERSION=1.0 ColdFusion's string functions can be used to parse out the relevant latitude and longitude data, as well as the city, state, and country. We'll then insert that info into the database and use it to populate a map overlay when each point is clicked. Listing 2 contains the code to parse out these fields. Another source of freely available geo-location data is the community-based hostip.info project located at http://www.hostip.info. Although this is a newer database, it's being actively and continuously updated and is improving with time. This database can also be queried via HTTP and returns the results in a format similar to NetGeo. A URL query to hostip.info would be structured as http://api.hostip.info/get_html.php?ip=64.19.164.74&position=true. You can also download the full hostip.info database directly to your server for quicker response time. There's also the commercial GeoIP City database maintained by MaxMind (see www.maxmind.com/app/city).
Drawing the Map Using Google To begin, put the script calls in Listing 3 in the <head></head> section of your page. Next, include an empty div right after your <body> tag. This will contain the actual map and determine its size: <div id="map" style="width: 700px; height: 500px"></div>
Using Yahoo!'s New Flex-Based API Then include an empty div right after your <body> tag. This div will contain the actual map: <div id="mapContainer" style="width: 700px; height: 500px"></div>
Microsoft's Virtual Earth Implementation As with most of Microsoft's technologies, Virtual Earth will probably take a few revisions before they get it right. Currently there are advantages to using the Google or Yahoo! APIs. Google offers simplicity and the capability to add detailed HTML overlays complete with images. Yahoo!'s advantage comes in its rich integration possibilities with Flash-based technologies as well as AJAX.
Troubleshooting
Taking It Even Further
Conclusion Resources
CFDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||