Seattle Movie Finder: An AJAX- and REST-Powered Virtual Earth Mashup
by Dare Obasanjo
|
Pages: 1, 2, 3, 4, 5
GeoCoding 101: Street Addresses to Latitudes and Longitudes
After learning how to embed a Virtual Earth map on a web page, the next thing I had to learn was how to add to the map a pushpin that corresponded to a physical location. As shown in the table in the previous section, adding a pushpin is done via the AddPushpin() method. However, there was a problem: the AddPushpin() method takes a latitude and longitude as input, while I knew only the street addresses of the movie theaters. I needed a way to convert the physical addresses of the theaters to latitudes and longitudes. This process is called geocoding.
To convert the addresses of the various movie theaters to latitudes and longitudes, I used the free services provided by the geocoder.us website.The website provides several options for geocoding addresses, from entering addresses into a web form to using a choice of SOAP, XML-RPC, or REST web services for mapping addresses to latitudes and longitudes.Thus it was quite straightforward for me to write a program that took a list of movie theaters in the Seattle area and obtained their latitudes and longitudes. Once I had obtained their latitudes and longitudes, I created an XML document where the information would be stored for use by my Seattle Movie Finder application.
Below is the XML schema for the list of movie theaters used by my Seattle Movie Finder service.
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="theaters" type="MovieTheaters"/>
<xs:complexType name="MovieTheaters">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="theater" type="MovieTheater"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MovieTheater">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="name" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="address" type="xs:string"/>
<xs:element minOccurs="1" maxOccurs="1" name="lat" type="xs:double"/>
<xs:element minOccurs="1" maxOccurs="1" name="long" type="xs:double"/>
<xs:element minOccurs="0" maxOccurs="1" name="movies" type="ArrayOfMovie"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfMovie">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="movie" type="Movie"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Movie">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="name" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="times" type="ArrayOfString"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfString">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="time" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
And below is an example of the XML document representing the various movie theaters in the Seattle area.
<theaters>
<theater>
<name>Cinerama 1</name>
<address>2100 4th Ave., Seattle, WA, 98121</address>
<lat>47.61402</lat>
<long>-122.341337</long>
</theater>
<theater>
<name>Pacific Place 11</name>
<address>600 Pine S., Suite 400, Seattle, WA, 98101</address>
<lat>47.612320</lat>
<long>-122.335137</long>
</theater>
<theater>
<name>Loews Meridian 16</name>
<address>1501 7th Ave, Seattle, WA 98101</address>
<lat>47.611820</lat>
<long>-122.333137</long>
</theater>
<theater>
<name>Loews Oak Tree Cinemas 6</name>
<address>10006 Aurora Ave. N., Seattle, WA 98133</address>
<lat>47.701563</lat>
<long>-122.344545</long>
</theater>
<theater>
<name>Loews Uptown</name>
<address>511 Queen Anne Ave N., Seattle, WA, 98109</address>
<lat>47.623647</lat>
<long>-122.356631</long>
</theater>
<!-- more theaters left out due to space constraints -->
</theaters>