Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 3 — The Google Maps API 51


Because GXmlcreates a persistent object that you then use to parse and access XML data, you
should take care to ensure that you are using the correct object when accessing a value.
Although in some situations it is tempting to reuse the same object to parse an XML document,
it may return an odd value if you use the wrong object or forget to reparse the XML you wanted.


GXslt


When providing additional information on a Google Map (for example, within an info win-
dow when the user clicks a map point), you can use XSLT to convert a supplied XML docu-
ment into the HTML to be displayed.


The GXsltfunction creates a new object that supports a browser-independent method for trans-
lating XML data into HTML through the supplied XSLT transformation definition. The con-
version tries to use the native XSLT transformation library built into the browser if it is available
(it automatically picks a solution based on the browser). If no built-in XSLT engine is available, it
defaults to the XSLT transformation engine available within the JavaScript definition.


To create a new object by supplying the URI of an XSLT document, use the following:


GXSlt(xsltURI)


To perform a transformation, use the transformToHtmlmethod:


transformToHtml(xmlDoc, htmlContainer)


The preceding transforms the supplied XML document directly into the HTML DOM ele-
ment in a web page identified by the htmlContainerargument. It doesnotreturn the
HTML.


GPoint


This class creates a new GPointobject representing a two-dimensional coordinate (horizon-
tal/vertical):


GPoint(x,y)


If you use GPointto create a point on the map,xrepresents the longitude and yrepresents
the latitude.


A common mistake with GPointis that it takes longitude (east-west) and then latitude (north-
south) as arguments, in that order, even though you commonly refer to a point on a map the
other way around. It is very easy to mistakenly swap the values and end up referring to a point
thousands of miles from your intended location.


GSize


This class creates a new GSizeobject designed to represent a two-dimensional size measure-
ment (such as width and height). The format of the function is as follows:


GSize(width, height)

Free download pdf