I am working on a web page with Google App Engine. It involves html, python, javascript and Ajax.
The workflow would be like this:
when someone introduces a value in an html box, it calls a javascript function:
INPUT type="text" id="busca" name="busca" onblur="SacarMapa()"
That will call this function:
function SacarMapa()
{
var lugar=document.getElementById("busca").value;
$.ajax("/mapa",
{ "type": "get",
"data": {busca:lugar},
// usualmente post o get
"success": function(result) {
initMap(RESULT-A, RESULT-B);
},
"error": function(result) {
console.error("Se ha producido un error: ", result);},
"async": true,})};
What i would need is RESULT-A and RESULT-B. This would come from the server side, where python is used:
class MapHandler(SessionModule.BaseSessionHandler):
def get(self):
#Obtencion de datos
serviceurl = 'http://maps.googleapis.com/maps/api/geocode/json?'
address=self.request.get('busca')
self.response.out.write("Busca es "+address)
url = serviceurl + urllib.urlencode({'address': address})
uh = urllib.urlopen(url)
data = uh.read()
js = json.loads(str(data))
resultado = js['status']
if not resultado == "ZERO_RESULTS":
location = js['results'][0]['formatted_address']
latitud = js['results'][0]['geometry']['location']['lat']
longitud = js['results'][0]['geometry']['location']['lng']
So i would need to send "latitud" and "longitud" from the python code to javascript so that latitud would be RESULT-A and longitud RESULT-B
What would be the way to do this?
Thanks.
{'RESULT-A': latitud, 'RESULT-B': longitud}?