def calcular_ruta_por_dir(request): origen = request.POST['origen'] destino = request.POST['destino'] preferencia = request.POST.get('preferencia', 'seguridad') coord_origen = geo.geocode(origen) coord_destino = geo.geocode(destino) if not ('error' in coord_origen or 'error' in coord_destino): ruta = json.dumps( geo.routingExec(coord_origen['lng'], coord_origen['lat'], coord_destino['lng'], coord_destino['lat'], preferencia) ) response = HttpResponse(ruta, content_type="application/json") else: if 'error' in coord_origen: error = 'Direccion origen desconocida' elif 'error' in coord_destino: error = 'Direccion destino desconocida' response = HttpResponse({'error': error}, content_type="application/json") response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Headers'] = 'X-Requested-With' return response
def sitios_por_dir(request): direccion = request.POST['direccion'] tipo_sitio = request.POST['tipo_sitio'] coord_direccion = geo.geocode(direccion) radio = '0.01' if not ('error' in coord_direccion ): sitios = json.dumps( geo.findNearestSites(coord_direccion['lat'], coord_direccion['lng'], tipo_sitio, radio)) response = HttpResponse(sitios, content_type="application/json") else: error = 'Direccion desconocida' response = HttpResponse({'error': error}, content_type="application/json") response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Headers'] = 'X-Requested-With' return response