<div class="gmail_quote">2009/12/15 Lorenzo Macchiavelli <span dir="ltr"><<a href="mailto:lmacchiavelli@gmail.com">lmacchiavelli@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Ciao<div> Siccome ho avuto la stessa problematica tempo fa<div>c'è questo che troverai di sicura utilità!!!</div><div><a href="http://darcas.net/index.php/2008/10/12/calcolo-della-distanza-tra-due-punti-geografici/" target="_blank">http://darcas.net/index.php/2008/10/12/calcolo-della-distanza-tra-due-punti-geografici/</a></div>
</div></blockquote><div><br>Se poi vuoi sapere le coordinate partendo da un indirizzo usa lo script python che allego in fondo.<br>Ciao.<br>Marco.<br clear="all"></div></div><br>-- <br><a href="http://ThinkCode.TV">http://ThinkCode.TV</a> - Screencast e videocorsi di programmazione<br>
<a href="http://stacktrace.it">http://stacktrace.it</a> - Aperiodico di resistenza informatica<br><a href="http://beri.it">http://beri.it</a> - Blog di una testina di vitello<br><br>###############################<br># gmaps.py<br>
###############################<br><br>import urllib<br>try:<br> from django.utils.http import urlencode<br>except ImportError:<br> from textutils import unicode_urlencode as urlencode<br>from time import sleep<br>
<br>
key = "<qui ci metti la tua chiave per le API di Google>"<br><br>def location2latlong( query, key=key ):<br> """Get the ( latitute, longitude ) coordinates corresponding<br> to the query. If something goes wrong return None."""<br>
<br> output = 'csv'<br><br> params = { }<br> params[ 'key' ] = key<br> params[ 'output' ] = output<br> params[ 'q' ] = query<br><br> params = urlencode( params )<br><br> try:<br>
f = urllib.urlopen("<a href="http://maps.google.com/maps/geo?%s">http://maps.google.com/maps/geo?%s</a>" % params )<br> except IOError:<br> # maybe some local problem at google? let's try again<br>
sleep( 3 )<br> try:<br> f = urllib.urlopen("<a href="http://maps.google.com/maps/geo?%s">http://maps.google.com/maps/geo?%s</a>" % params )<br> except IOError:<br> # okay we give up<br>
return None<br><br> response = f.read( ).split(',')<br> f.close( )<br><br> try:<br> status = response[0]<br> accuracy = response[1]<br> latitude = response[2]<br> longitude = response[3]<br>
except:<br> return None<br><br> if status != '200':<br> return None<br> else:<br> return latitude, longitude<br><br>if __name__ == '__main__':<br> import sys<br> try:<br>
q = sys.argv[1]<br> except:<br> print 'Usage: python gmaps.py query'<br> sys.exit( 1 )<br><br> r = location2latlong( q )<br> if r is not None:<br> print r<br> else:<br> print 'Something went wrong.'<br>
<br><br>