Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion

ColdFusion: Article

An In-Depth Look at Mapping APIs

The benefits and drawbacks

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.

Geo-locating by IP Address
Let's go over our example one more time. We're going to use these tools to create a visual map of users visiting your site. You'll be able to show these on a custom map along with any other text or HTML data you'd like to display. One of the key ingredients to this technique is the ability to geo-locate an IP address. This refers to the ability to locate a user's geographic latitude and longitude from his IP address. The most cost-effective source of this information is to query one of the freely available public databases. NetGeo was a project originally set up by the Cooperative Association for Internet Data Analysis (CAIDA). Although it has been defunct for several years, the database is still freely available and provides a good resource for determining rough locations.

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
TARGET: 64.19.164.74
NAME: MONMOUTH-BLK2
NUMBER: 64.19.128.0 - 64.19.191.255
CITY: RED BANK
STATE: NEW JERSEY
COUNTRY: US
LAT: 40.35
LONG: -74.08
LAT_LONG_GRAN: City
LAST_UPDATED: 01-Jun-2001
NIC: ARIN
LOOKUP_TYPE: Block Allocation
RATING:
DOMAIN_GUESS: MONMOUTH.COM
STATUS: OK

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
The first thing you'll need to do is to sign up for a Google Maps API key at www.google.com/apis/maps/. This key will have to be included on any pages on which you'll be drawing maps.

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
You'll also have to get an application ID from Yahoo! before using its service. Once that's done, you'll put script calls in Listing 4 in the <head></head> section of your page.

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
Interfacing with Microsoft's Virtual Earth is also relatively painless. Most of your code will go in the <head></head> section of the page. The code you'll need to include is in Listing 5. Then you'll have to add an onLoad call to your body tag as follows: <body onLoad="OnPageLoad()">.

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
One thing to note is that some browsers will throw a security error when trying to access a JavaScript file from a different domain. You can get around this by downloading the .js file to your server and serving it up locally.

Taking It Even Further
The Yahoo! map that we built, though Flash-based, used the JavaScript API to interact with the map. There's also an ActionScript API available for direct integration with Flash as well as a Flex API to interact with maps directly from your RIAs. This comes at a great time with Macromedia's recent announcements regarding the Flex product line. Check this link under resources for a great example of what can be done with the Flash API: http://tinyurl.com/avpv8 (from Justin's Rich Media Blog). The APIs will also accept geo-coded RSS feeds. This lets you fuse live data right on to your maps, such as being able to plot apartments currently listed for rent through craigslist.

Conclusion
We've only scratched the surface of what can be done using the new mapping APIs that are now available. It's possible to create all kinds of applications based on geographic data. Although the licensing terms for each API are slightly different, they are generally pretty liberal and even allow for commercial use in some cases. Visit the links provided for full documentation on each of them.

Resources

More Stories By Joe Danziger

Joe Danziger is a senior web applications developer with Multimax, Inc., a provider of Enterprise IT Services and Solutions supporting the critical missions of the Air Force, Army, Navy, and other Department of Defense components. He is certified as an Advanced Macromedia ColdFusion MX Developer, and also maintains the Building Blocks site (www.ajaxcf.com) dedicated to AJAX and ColdFusion, as well as DJ Central (www.djcentral.com), a Website serving DJs and the electronic dance music industry.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
SYS-CON Events announced today that Dasher Technologies will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Dasher Technologies, Inc. ® is a premier IT solution provider that delivers expert technical resources along with trusted account executives to architect and deliver complete IT solutions and services to help our clients execute their goals, plans and objectives. Since 1999, we'v...
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp emp...
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
SYS-CON Events announced today that TidalScale, a leading provider of systems and services, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. TidalScale has been involved in shaping the computing landscape. They've designed, developed and deployed some of the most important and successful systems and services in the history of the computing industry - internet, Ethernet, operating s...
Infoblox delivers Actionable Network Intelligence to enterprise, government, and service provider customers around the world. They are the industry leader in DNS, DHCP, and IP address management, the category known as DDI. We empower thousands of organizations to control and secure their networks from the core-enabling them to increase efficiency and visibility, improve customer service, and meet compliance requirements.
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant tha...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, will lead you through the exciting evolution of the cloud. He'll look at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering ...
In a recent survey, Sumo Logic surveyed 1,500 customers who employ cloud services such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP). According to the survey, a quarter of the respondents have already deployed Docker containers and nearly as many (23 percent) are employing the AWS Lambda serverless computing framework. It’s clear: serverless is here to stay. The adoption does come with some needed changes, within both application development and operations. Tha...
SYS-CON Events announced today that Avere Systems, a leading provider of enterprise storage for the hybrid cloud, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Avere delivers a more modern architectural approach to storage that doesn't require the overprovisioning of storage capacity to achieve performance, overspending on expensive storage media for inactive data or the overbui...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
SYS-CON Events announced today that TidalScale will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. TidalScale is the leading provider of Software-Defined Servers that bring flexibility to modern data centers by right-sizing servers on the fly to fit any data set or workload. TidalScale’s award-winning inverse hypervisor technology combines multiple commodity servers (including their ass...
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...
As hybrid cloud becomes the de-facto standard mode of operation for most enterprises, new challenges arise on how to efficiently and economically share data across environments. In his session at 21st Cloud Expo, Dr. Allon Cohen, VP of Product at Elastifile, will explore new techniques and best practices that help enterprise IT benefit from the advantages of hybrid cloud environments by enabling data availability for both legacy enterprise and cloud-native mission critical applications. By rev...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant th...
Digital transformation is changing the face of business. The IDC predicts that enterprises will commit to a massive new scale of digital transformation, to stake out leadership positions in the "digital transformation economy." Accordingly, attendees at the upcoming Cloud Expo | @ThingsExpo at the Santa Clara Convention Center in Santa Clara, CA, Oct 31-Nov 2, will find fresh new content in a new track called Enterprise Cloud & Digital Transformation.
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
Most technology leaders, contemporary and from the hardware era, are reshaping their businesses to do software. They hope to capture value from emerging technologies such as IoT, SDN, and AI. Ultimately, irrespective of the vertical, it is about deriving value from independent software applications participating in an ecosystem as one comprehensive solution. In his session at @ThingsExpo, Kausik Sridhar, founder and CTO of Pulzze Systems, will discuss how given the magnitude of today's applicati...
What is the best strategy for selecting the right offshore company for your business? In his session at 21st Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, will discuss the things to look for - positive and negative - in evaluating your options. He will also discuss how to maximize productivity with your offshore developers. Before you start your search, clearly understand your business needs and how that impacts software choices.