Skip to main content
POST
/
rutas
/
generar-desde-poi
curl -X POST https://api.tesisrutas.com/rutas/generar-desde-poi \
  -H "Content-Type: application/json" \
  -d '{
    "poi_id": "507f1f77bcf86cd799439011",
    "cantidad": 5
  }'
{
  "nombre": "Ruta recomendada desde Catedral Metropolitana",
  "descripcion": "Ruta ordenada automáticamente por cercanía geográfica.",
  "categoria": "",
  "puntos": [
    {
      "poi_id": "507f1f77bcf86cd799439011",
      "order": 0,
      "nombre": "Catedral Metropolitana"
    },
    {
      "poi_id": "507f1f77bcf86cd799439012",
      "order": 1,
      "nombre": "Plaza de Armas"
    },
    {
      "poi_id": "507f1f77bcf86cd799439013",
      "order": 2,
      "nombre": "Palacio Municipal"
    },
    {
      "poi_id": "507f1f77bcf86cd799439014",
      "order": 3,
      "nombre": "Museo Histórico"
    },
    {
      "poi_id": "507f1f77bcf86cd799439015",
      "order": 4,
      "nombre": "Casa de la Cultura"
    },
    {
      "poi_id": "507f1f77bcf86cd799439016",
      "order": 5,
      "nombre": "Teatro Principal"
    }
  ],
  "creado_en": "2024-03-15T14:30:00Z"
}
Automatically generates a recommended tourist route starting from a specific POI. The system uses geographic proximity algorithms to create an optimal route through nearby points of interest.

Authentication

No authentication required. This is a public endpoint for route discovery.
poi_id
string
required
ID of the starting POI from which to generate the route
cantidad
integer
default:"5"
Number of additional POIs to include in the generated route (default: 5)

AI Generation Algorithm

The route generation uses a proximity-based algorithm:
  1. Fetch Starting POI: Retrieves the initial POI with coordinates
  2. Load All POIs: Gets all active POIs from the database
  3. Calculate Distances: Uses Haversine formula to compute distances:
    R = 6371  # Earth radius in km
    dlat = radians(lat2 - lat1)
    dlng = radians(lng2 - lng1)
    a = sin(dlat/2+ cos(lat1) * cos(lat2) * sin(dlng/2
    c = 2 * atan2(sqrt(a), sqrt(1-a))
    distance = R * c
    
  4. Sort by Proximity: Orders all POIs by distance from starting point
  5. Select Nearest: Picks the N closest POIs
  6. Build Route: Constructs ordered route with metadata
See generar_ruta_desde_poi.py:18-84 for implementation.
nombre
string
Auto-generated route name (e.g., “Ruta recomendada desde Plaza Mayor”)
descripcion
string
Description indicating automatic generation method
categoria
string
Category (empty for auto-generated routes)
puntos
array
Ordered array of POIs in the generated route
poi_id
string
ID of the POI
order
integer
Position in the route (0 = starting POI)
nombre
string
Name of the POI (included for convenience)
creado_en
string
Timestamp of generation
curl -X POST https://api.tesisrutas.com/rutas/generar-desde-poi \
  -H "Content-Type: application/json" \
  -d '{
    "poi_id": "507f1f77bcf86cd799439011",
    "cantidad": 5
  }'
{
  "nombre": "Ruta recomendada desde Catedral Metropolitana",
  "descripcion": "Ruta ordenada automáticamente por cercanía geográfica.",
  "categoria": "",
  "puntos": [
    {
      "poi_id": "507f1f77bcf86cd799439011",
      "order": 0,
      "nombre": "Catedral Metropolitana"
    },
    {
      "poi_id": "507f1f77bcf86cd799439012",
      "order": 1,
      "nombre": "Plaza de Armas"
    },
    {
      "poi_id": "507f1f77bcf86cd799439013",
      "order": 2,
      "nombre": "Palacio Municipal"
    },
    {
      "poi_id": "507f1f77bcf86cd799439014",
      "order": 3,
      "nombre": "Museo Histórico"
    },
    {
      "poi_id": "507f1f77bcf86cd799439015",
      "order": 4,
      "nombre": "Casa de la Cultura"
    },
    {
      "poi_id": "507f1f77bcf86cd799439016",
      "order": 5,
      "nombre": "Teatro Principal"
    }
  ],
  "creado_en": "2024-03-15T14:30:00Z"
}

Use Cases

  • Quick Route Discovery: Tourists can instantly get route suggestions
  • Route Planning: Use as a starting point before manual customization
  • Mobile Apps: Provide “Near Me” route generation
  • Kiosks: Auto-generate routes from current location

Important Notes

This endpoint generates a route object but does NOT save it to the database. To save, use the Create Route endpoint with the returned data.
  • Generated routes are optimized for walking distance
  • Only includes active POIs from the database
  • Starting POI is always position 0
  • Route is NOT automatically saved
  • Default quantity is 5 additional POIs (6 total including start)

Error Responses

  • 404 Not Found: Starting POI does not exist
  • 422 Unprocessable Entity: Invalid request format

Build docs developers (and LLMs) love