Created
April 12, 2012 13:08
-
-
Save nattomi/2367095 to your computer and use it in GitHub Desktop.
simplyfied addPOIexec example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import urllib2 | |
from xml.dom import minidom | |
values = {} | |
values["lat"] = 47.635 | |
values["lon"] = 16.7 | |
values["nearbyplace"] = "Unknown" | |
url = "http://ws.geonames.org/findNearbyPlaceName?lat=%s&lng=%s" % (values["lat"], values["lon"]) | |
try: | |
response = urllib2.urlopen(url) | |
except urllib2.URLError, e: | |
pass | |
else: | |
gnData = response.read() | |
dom = minidom.parseString(gnData) | |
if dom.getElementsByTagName('name'): | |
name = dom.getElementsByTagName('name')[0].firstChild.data | |
country = dom.getElementsByTagName('countryCode')[0].firstChild.data | |
values["nearbyplace"] = "%s [%s]" % (name, country) | |
print gnData | |
print values | |
print name | |
print values["nearbyplace"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
<geonames> | |
<geoname> | |
<toponymName>Fertőboz</toponymName> | |
<name>Fertőboz</name> | |
<lat>47.63638</lat> | |
<lng>16.70085</lng> | |
<geonameId>3052647</geonameId> | |
<countryCode>HU</countryCode> | |
<countryName>Hungary</countryName> | |
<fcl>P</fcl> | |
<fcode>PPL</fcode> | |
<distance>0.16601</distance> | |
</geoname> | |
</geonames> | |
{'lat': 47.635, 'lon': 16.7, 'nearbyplace': u'Fert\u0151boz [HU]'} | |
Fertőboz | |
Fertőboz [HU] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment