Google Maps is a free service that provides browser-based directions as well as maps of particular locations through the Internet. You can zoom in on the interactive maps to show detailed information, providing great user interactivity with the Web site. The maps provided by Google can be used not only directly by customers, but also to develop customized map services and products with the Google Maps API. The latest Google Maps API version, however, is not good at parsing Chinese geography, which makes it difficult to use in applications for a Chinese audience. In this article, we describe a feasible solution, combining other Web services, to parse Chinese geography with the current Google Maps API for a Chinese mapping solution. We'll use the example of the sites for the Beijing 2008 Olympic Games to demonstrate our solution.
Overview of Google Maps
Google Maps is the next generation of online mapping. With its smart and intuitive interface, you can search for just about anything—the name of a business, a point of interest, an address, or a city—and up will pop an attractive map. The map is easily panned and zoomed through mouse movements or keystrokes, and the street names and road outlines are crisply displayed. Equally impressive are Google Maps' driving directions, which are clear and follow the roads in vivid lines.
Additionally, Google supplies the Google Maps API. This API provides a number of utilities for manipulating and adding content to maps through a variety of services, allowing you to create robust map applications and embed Google Maps on your Web site.

| Back to top |
|
Normal solution to parse and display geography
 | Geocodes A geocode is some combination of geospacial parameters, such as longitude and latitude or altitude, that reference a specific location. |
|
The Google Maps API has one class, GClientGeocoder, which is used to communicate directly with Google servers to obtain geocodes for user-specified addresses. The geocoder maintains its own cache of addresses, allowing repeated queries to be answered without a round trip to the server. Normally, consumers can send a request to Google servers to geocode the specified address via the method GClientGeocoder.getLatLng(address, callback). As an example, when we pass "Shanghai" to this method, the point of the best matched address will be returned. The result here is (31.224353, 121.475916), which indicates the latitude and longitude of the city of Shanghai. The sample map with this function is shown in Figure 1.
Figure 1. The sample map with the function GClientGeocoder.getLatLng()
Listing 1 (see sidefile) shows the html source behind the map in Figure 1.

| Back to top |
|
The problem for Chinese geography
The GClientGeocoder class in Google Maps API works well for translating an English geographical site, but it's not good at Chinese geography. As an example, when passing in "中国北京国家体育馆" (the Beijing 2008 Olympic national gymnasium), GClientGeocoder can not work, as demonstrated in Figure 2.
Figure 2. The sample map with specifying Chinese geography site

| Back to top |
|
A new solution using Google's geography query Web service
Besides the GClientGeocoder class in the Google Maps API, there are Web services for translating Chinese geographical sites into (latitude, longitude) pairs. Among them, http://maps.google.com/maps/geo is one of Google's Web services for geography parsing. As a quick test, open a browser and type the following request string into the URL field:
http://maps.google.com/maps/geo?q=Chicago&output=cvs&key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xS
osDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA |
In the above query string, q is the target address for query, output is the response format, and key is the key string to use the Web service.
After pressing Enter, a dialog will appear in Internet Explorer to save the response string as shown in Figure 3. Firefox and other browsers may simply return the text, which you can save manually.
Figure 3. The dialog box for saving http response
 | Google accuracy constants Google accuracy constants denote the scale of the item returned, not the confidence of the item. Four represents something town-sized. Find definitions of these constants and their meanings in Google's API documentation (see Resources). |
|
Open the file and you can see the response string with complete translation information as shown in Listing 2 (see sidefile).
The final section: "Point":{"coordinates":[-87.624333,41.879535,0]}} is the translated (latitude, longitude) pair which can be used directly to locate it on Google Maps.
For simplicity, we can specify 'csv' rather than 'cvs' for 'output'. Then only four numbers are returned:
200,4,41.879535,-87.624333
|
Note: In the response, 200 is the HTTP status code, showing that the parsing was successful; 4 is an accuracy constant; 41.879535 is the longitude; -87.624333 is the latitude.
Then we try to pass in the Chinese geography site "中国北京国家体育馆" (the Beijing 2008 Olympic national gymnasium) as the target site:
http://maps.google.com/maps/geo?q=中国北京国家体育馆&output=csv&key=ABQIAAAAzr2EBOXUKnm_jVnk
0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA
|
The query service can successfully parse it to get the following (latitude, longitude) pair:
200,9,39.997005,116.390212
|
We can now use the query Web service as an alternative solution to overcome the disadvantage in the GClientGeocoder class. Figure 4 shows a diagram of the solution.
Figure 4. The solution overview
To display a geographical site on a Chinese map, the Geography Translation module will first send an http request to the parsing Web service, translating the location into a (latitude, longitude) pair. Then the Google Maps page will use the (latitude, longitude) pair to locate the site.

| Back to top |
|
Example: Displaying a driving route between two sites on a Chinese map
Listing 3 shows an example demonstrating our solution in action. To make it easy for readers to run on multiple platforms, we've written a simple Java application. It parses two Beijing 2008 Olympic sites and generates a Google Maps HTML page, on which the two sites are marked as 'A' and 'B' with a driving route between them marked in blue. Readers can also easily open a Web browser and display the generated Google Maps HTML page.
The translation module in Listing 3 (see sidefile) will send out an http request, as described above, retrieve the response string, and parse out the (latitude, longitude) pair. For simplicity, 'csv' will be used as the format of the http response string.
Note in Listing 3: The open source 'HttpClient' library by Apache (see Resources) is used for sending the http request and receiving the http response.
The AddrPoint class, shown in Listing 4, is just a bean class for the (latitude, longitude) pair:
Listing 4. AddrPoint Javabean
public static class AddrPoint {
private float _latitude=0;
private float _longtitude=0;
private String _name=null;
public AddrPoint(float longitude, float latitude, String name) {
_latitude=latitude;
_longitude=longitude;
_name=name;
}
/**
* @return Returns the _latitude.
*/
public float getLatitude() {
return _latitude;
}
/**
* @return Returns the _longitude.
*/
public float getLongitude() {
return _longtitude;
}
/**
* @return Returns the _name.
*/
public String getName() {
return _name;
}
}
|
To generate the Google Maps page, Apache's template engine, Velocity, is used (see Resources). Our page template follows in Listing 5 (see sidefile).
The generation codes are shown in Listing 6 (see sidefile).
Passing two Olympic sites "中国北京奥林匹克公园" (the Beijing 2008 Olympic Park) and "中国北京国家体育馆" (the Beijing 2008 Olympic national gymnasium) results in the generated Google Maps page shown in Figure 5.
Figure 5. The generated Google Maps page
Figure 6 shows the satellite view for site A (the Beijing 2008 Olympic Park).
Figure 6. The satellite map for site A
The satellite view for site B (the Beijing 2008 Olympic national gymnasium) is shown in Figure 7.
Figure 7. The satellite map for site B

| Back to top |
|
Summary
Google Maps is a hot technology and service that customers can use to develop their own customized map services, based on the Google Maps API. This article introduces a solution for Chinese geographical site translation to fix the problem in the default translation class, GClientGeocoder. The example showing the Beijing 2008 Olympic sites demonstrates the feasibility of this solution and shows how services can be combined to overcome limitations.