Its a fairly simple implementation of a xml reader combined with a
distance calculator. Once the current location of lat long is passed
to this code from the PointAbout mobile software. It is an example of how basic code and location information can completly change the use and power of simple data streams and web sites.
An example xml doc is also appended to the bottom of this post for testing.
—-EXAMPLE OF DISTANCE FORMULA—-
def getDistance(fromLat, fromLong, toLat, toLong ):
lat1 = float(fromLat)
lon1 = float(fromLong)
R = 6371; # km
lat2 = toLat
lon2 = toLong
dLat = math.radians(lat2-lat1)
dLon = math.radians(lon2-lon1)
a = math.sin(dLat/2) * math.sin(dLat/2) +
math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) *
math.sin(dLon/2) * math.sin(dLon/2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
d = R * c
return d
——EXAMPLE OF XML TO ORDERED BY DISTANCE———–
#logging.info(file_xml.toxml())
listings = {}
for item in itemNodeSub:
try: name = item.childNodes[1].childNodes[0].data
except: name = None
try:
html = item.childNodes[2].childNodes[0].data
p = re.compile(“ADDRESS:</td><td>(.*?)</td>”)
m = p.search(html)
address = m.group(1)
city = “Washington”
state = “DC”
address = address + ” ” + city + “, ” + state
except:
address = “No Data”
logging.debug(“Error”)
data = {
”name”:name,
”address”:address,
}
distance = 0.0
try:
lng, lat, alt =
item.childNodes[4].childNodes[1].childNodes[0].data.split(“,”)
distance = getDistance(currLat , currLng,
float(lat.strip()), float(lng.strip()))
except:
lat = None
lng = None
search = requestHandler.get(“search”)
if search == None or name.lower().find(search.lower()) >= 0:
listings.update({distance:[data, round(distance,2)]})
orderedListing = sortedDictValues1(listings)
——-SAMPLE OF XML FEED—–
<kml xmlns=”http://earth.google.com/kml/2.2″
xmlns:atom=”http://www.w3.org/2005/Atom”>
<Document>
<open>1</open>
<name><![CDATA[Layers]]></name>
<Folder><name>Legend</name><visibility>0</visibility><ScreenOverlay><name>Legend</name><visibility>0</visibility><overlayXY
x=”0″ y=”1″ xunits=”fraction” yunits=”fraction” /><screenXY x=”0″
y=”1″ xunits=”fraction” yunits=”fraction”
/><Icon><href>legend.png</href></Icon></ScreenOverlay></Folder>
<Folder><name><![CDATA[Banks]]></name>
<visibility>1</visibility>
<open>1</open>
<Folder><name>Data</name><visibility>1</visibility>
<Placemark id=”pm5504″ ><Snippet
maxLines=”0″>empty</Snippet><name><![CDATA[Adams
Bank]]></name><description><![CDATA[<b><font size="4"face="Arial">Bank
Locations</b><p></p><table cellpadding="1"
cellspacing="1"><tr><td>NAME:</td><td>Adams
Bank</td></tr><tr><td>ADDRESS:</td><td>1729 Wisconsin Ave,
NW</td></tr><tr><td>ZIPCODE:</td><td>20007</td></tr><tr><td>ADDRESS_ID:</td><td>275259</td></tr></table><p></p><b><font
size="4" face="arial"><form>Provided by: </form></b><a
href="http://dcgis.dc.gov/">District of Columbia
GIS</a>]]></description><styleUrl>#Style_92</styleUrl><Point
id=”g7177″><altitudeMode>clampedToGround</altitudeMode><coordinates>-77.0668994099031,38.9145339105088,1
</coordinates></Point></Placemark><Placemark id=”pm5505″ ><Snippet
maxLines=”0″>empty</Snippet><name><![CDATA[Adams
Bank]]></name><description><![CDATA[<b><font size="4"face="Arial">Bank
Locations</b><p></p><table cellpadding="1"
cellspacing="1"><tr><td>NAME:</td><td>Adams
Bank</td></tr><tr><td>ADDRESS:</td><td>1501 K Street,
NW</td></tr><tr><td>ZIPCODE:</td><td>20006</td></tr><tr><td>ADDRESS_ID:</td><td>279201</td></tr></table><p></p><b><font
size="4" face="arial"><form>Provided by: </form></b><a
href="http://dcgis.dc.gov/">District of Columbia
GIS</a>]]></description><styleUrl>#Style_92</styleUrl><Point
id=”g7178″><altitudeMode>clampedToGround</altitudeMode><coordinates>-77.0351181683022,38.9029520625695,1
</coordinates></Point></Placemark><Placemark id=”pm5506″ ><Snippet
maxLines=”0″>empty</Snippet><name><![CDATA[Adams
Bank]]></name><description><![CDATA[<b><font size="4"face="Arial">Bank
Locations</b><p></p><table cellpadding="1"
cellspacing="1"><tr><td>NAME:</td><td>Adams
Bank</td></tr><tr><td>ADDRESS:</td><td>50 Massachusetts, Avenue,
SE</td></tr><tr><td>ZIPCODE:</td><td>20002</td></tr><tr><td>ADDRESS_ID:</td><td>293243</td></tr></table><p></p><b><font
size="4" face="arial"><form>Provided by: </form></b><a
href="http://dcgis.dc.gov/">District of Columbia
GIS</a>]]></description><styleUrl>#Style_92</styleUrl><Point
id=”g7179″><altitudeMode>clampedToGround</altitudeMode><coordinates>-77.0061791229437,38.8975384697844,1
</coordinates></Point></Placemark></Folder></Folder>
<StyleMap id=”Style_92″
><Pair><key>normal</key><styleUrl>#Style_92n</styleUrl></Pair><Pair><key>highlight</key><styleUrl>#Style_92h</styleUrl></Pair><BalloonStyle><color>ffdcf5f5</color><textColor>ff000000</textColor><text><![CDATA[
$[description] ]]></text></BalloonStyle></StyleMap><Style
id=”Style_92n”><IconStyle><scale>0.5</scale><Icon><href>Style_92n.png</href></Icon></IconStyle><PolyStyle><fill>1</fill><color>ff00a838</color><outline>0</outline></PolyStyle><LabelStyle><scale>0</scale></LabelStyle><BalloonStyle><color>ffdcf5f5</color><textColor>ff000000</textColor><text><![CDATA[
$[description] ]]></text></BalloonStyle></Style><Style
id=”Style_92h”><IconStyle><scale>0.5</scale><Icon><href>Style_92h.png</href></Icon></IconStyle><PolyStyle><fill>1</fill><color>ff00a838</color><outline>0</outline></PolyStyle><LabelStyle><color>ffffffff</color><scale>1</scale></LabelStyle><BalloonStyle><color>ffdcf5f5</color><textColor>ff000000</textColor><text><![CDATA[
$[description] ]]></text></BalloonStyle></Style>
</Document></kml>
BANKS Near Me, Right Now [PointAbout] | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]
BUILDING PERMITS Near Me, Right Now [PointAbout] | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]
CONSTRUCTION PROJECTS Near Me, Right Now [PointAbout] | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]
EMBASSIES Near Me, Right Now [PointAbout] | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]
GAS STATIONS Near Me, Right Now [PointAbout] | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]
HOTELS Near Me, Right Now [PointAbout] | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]
LIBRARIES Near Me, Right Now [PointAbout] | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]
MARINAS Near Me, Right Now [PointAbout] | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]
POLICE STATIONS Near Me, Right Now [PointAbout] | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]
POST OFFICES Near Me, Right Now [PointAbout] | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]
PLACES OF WORSHIP Near Me, Right Now [PointAbout] | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]
DC Location - Aware Realtime Alerts | Apps for Democracy said
[...] Code Location: http://pointabout.wordpress.com/2008/12/01/example-of-source-used-for-apps-for-democracy-submission/ [...]