Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

52 Part I — Basics


Here,widthand heightare the appropriate spans. These can be any floating-point value,
but are usually used to hold latitude/longitude values.

GBounds


This class creates a new object that represents a two-dimensional bounding box. You would
normally use GBoundsto determine whether a given GPointwas within a specified range. To
create a new GBoundsobject, use this:
GBounds(minX,minY,maxX,maxY)

Here, the arguments are usually the latitude and longitude of the box, although they can hold
any floating-point values.

Wrapping Up


Probably the hardest part of the process in developing a Google Map is understanding the rela-
tionship between the HTML used for the web page and the JavaScript used to integrate with
the Google Maps service. Although, in practice, you are embedding the JavaScript for the
application into an HTML page, the two should really be considered as separate elements that
are merely contained within the same file.

Once you understand that little piece of the puzzle (that is, using the class interface to the
Google Maps system and largely ignoring the HTML that acts as a wrapper around it), it
becomes easy to start developing Google Maps applications. The Google Maps class interface
is simple but effective, and throughout the rest of the book you will see that this simplicity
makes it easy to develop complex sites with rich functionality — without getting bogged down
in complicated interfaces.

Converting Degrees to Decimal

If you know the longitude and latitude of a given point in the degrees, minutes, and seconds
format (for example, 52° 54’ 40” N 0° 38’ 21” W), you can convert each value into its decimal
equivalent using the following formula:

decimal = degrees + (minutes/60) + (seconds/3600)

Taking the preceding example map reference:

Longitude = 0 + (38/60) + (21/3600) = 0.6391666

Latitude = 52 + (54/60) + (40/3600) = 52.911111

These values can now be inserted directly into your Google Maps pages, databases, and data
stores when you create maps.
Free download pdf