> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/Braian551/viax/llms.txt
> Use this file to discover all available pages before exploring further.

# Location Sharing

> Share your trip location in real-time with friends and family for safety

## Overview

Viax's location sharing feature allows you to share your real-time trip location with trusted contacts. This safety feature gives your friends and family peace of mind by letting them track your journey from pickup to destination.

## Why Share Your Location

<CardGroup cols={2}>
  <Card title="Safety" icon="shield">
    Let others know where you are during your trip
  </Card>

  <Card title="Coordination" icon="users">
    Help others know when you'll arrive
  </Card>

  <Card title="Peace of Mind" icon="heart">
    Give your family assurance during travel
  </Card>

  <Card title="Accountability" icon="eye">
    Additional layer of security and transparency
  </Card>
</CardGroup>

## How Location Sharing Works

Location sharing creates a unique, time-limited link that displays your trip on a live map:

<Steps>
  <Step title="Start your trip">
    Book and begin your Viax trip as normal
  </Step>

  <Step title="Tap share icon">
    During the trip, tap the share location button in the tracking screen
  </Step>

  <Step title="Choose sharing method">
    Share via WhatsApp, SMS, email, or copy link

    ```dart theme={null}
    // Generate share token
    final shareToken = await locationSharingService.createToken(
      tripId: currentTrip.id,
      expiresIn: Duration(hours: 2),
    );

    final shareUrl = AppConfig.buildShareUrl(shareToken);
    // https://viaxcol.online/share/abc123xyz
    ```
  </Step>

  <Step title="Recipients view live map">
    Anyone with the link can view your real-time location
  </Step>

  <Step title="Auto-expiration">
    Link expires automatically after trip completion or 2 hours
  </Step>
</Steps>

## Creating a Share Link

The app generates a secure, temporary share link:

```dart theme={null}
// Location sharing implementation
class LocationSharingService {
  Future<String> createShareToken({
    required String tripId,
    Duration expiresIn = const Duration(hours: 2),
  }) async {
    final token = _generateSecureToken();
    
    final response = await http.post(
      Uri.parse('${AppConfig.baseUrl}/location_sharing/create.php'),
      body: {
        'trip_id': tripId,
        'token': token,
        'expires_in': expiresIn.inSeconds.toString(),
      },
    );
    
    if (response.statusCode == 200) {
      return token;
    }
    throw Exception('Failed to create share token');
  }
}
```

## What Recipients See

When someone opens your share link, they see:

<Tabs>
  <Tab title="Live Map">
    * Your current location (updated every 5 seconds)
    * Pickup point
    * Destination
    * Planned route
    * Driver location
    * Vehicle information
  </Tab>

  <Tab title="Trip Information">
    * Passenger name (you)
    * Trip status (en route, in progress, completed)
    * Estimated time of arrival
    * Distance remaining
    * Last updated timestamp
  </Tab>

  <Tab title="Driver Details">
    * Driver name
    * Vehicle type and plate number
    * Driver rating
    * Contact option (masked number)
  </Tab>
</Tabs>

<Note>
  Recipients don't need the Viax app installed - the share link opens in any web browser.
</Note>

## Share Link Structure

The location share URL contains:

```
https://viaxcol.online/share/{share_token}

Example:
https://viaxcol.online/share/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
```

### Token Components

```json theme={null}
{
  "trip_id": "12345",
  "user_id": "67",
  "expires_at": "2024-03-05T16:30:00Z",
  "permissions": ["view_location", "view_trip_details"]
}
```

## Sharing Methods

Multiple ways to share your trip:

<Accordion title="WhatsApp">
  ```
  I'm on a Viax trip. Track my location:
  https://viaxcol.online/share/abc123

  From: Calle 72 #10-34
  To: Carrera 15 #85-23
  ETA: 15 minutes
  ```

  * Instant delivery
  * Most popular in Colombia
  * Read receipts
  * Group sharing option
</Accordion>

<Accordion title="SMS">
  ```
  Following my Viax trip:
  https://viaxcol.online/share/abc123
  ```

  * Works on any phone
  * No app required
  * Reliable delivery
  * Good for emergencies
</Accordion>

<Accordion title="Email">
  Subject: Track My Viax Trip

  ```
  Hi,

  I'm currently on a Viax trip. You can track my location here:
  https://viaxcol.online/share/abc123

  Pickup: Calle 72 #10-34, Bogotá
  Destination: Carrera 15 #85-23, Bogotá
  ETA: 3:45 PM

  This link expires in 2 hours.
  ```
</Accordion>

<Accordion title="Copy Link">
  Copy the URL to share through:

  * Social media
  * Messaging apps
  * Notes/reminders
  * Anywhere else you choose
</Accordion>

## Privacy and Security

<CardGroup cols={2}>
  <Card title="Temporary Links" icon="clock">
    Share links expire automatically after trip completion
  </Card>

  <Card title="Unique Tokens" icon="key">
    Each share creates a unique, non-guessable token
  </Card>

  <Card title="No Personal Data" icon="user-secret">
    Recipients only see trip details, not your personal information
  </Card>

  <Card title="Revocable" icon="ban">
    Stop sharing anytime by ending the trip
  </Card>
</CardGroup>

### What's Not Shared

* Your phone number
* Email address
* Payment information
* Past trip history
* Saved addresses
* Other personal data

## Real-Time Updates

The share page updates your location automatically:

```javascript theme={null}
// Share page auto-refresh
setInterval(async () => {
  const tripData = await fetch(
    `https://api.viax.com/location_sharing/${token}`
  ).then(r => r.json());
  
  // Update marker position
  updateUserMarker(tripData.current_location);
  updateDriverMarker(tripData.driver_location);
  updateETA(tripData.estimated_arrival);
  updateTripStatus(tripData.status);
}, 5000); // Every 5 seconds
```

<Info>
  Location updates every 5 seconds to provide real-time tracking without excessive data usage.
</Info>

## Share Page Features

The web-based share page includes:

### Interactive Map

* Zoom and pan controls
* Full screen option
* Traffic layer toggle
* Satellite view
* Route visualization

### Trip Progress

* Progress bar showing % complete
* Distance traveled vs remaining
* Time elapsed vs ETA
* Current speed (optional)

### Emergency Contact

* Quick access to emergency services
* Contact Viax support
* Report issue button

## Use Cases

<Tabs>
  <Tab title="Late Night Trips">
    Share your location when traveling alone at night for added safety and peace of mind.
  </Tab>

  <Tab title="Meeting Coordination">
    Let meeting participants know your exact ETA and current location.
  </Tab>

  <Tab title="Family Trips">
    Parents can track children's trips to/from school or activities.
  </Tab>

  <Tab title="Business Travel">
    Share trip details with colleagues or assistants for coordination.
  </Tab>

  <Tab title="Airport Pickups">
    Help others time their departure to meet you at arrival.
  </Tab>
</Tabs>

## Managing Active Shares

View and manage your location shares:

```dart theme={null}
// View active shares
final activeShares = await locationSharingService.getActiveShares();

for (final share in activeShares) {
  print('Token: ${share.token}');
  print('Trip: ${share.tripId}');
  print('Expires: ${share.expiresAt}');
  print('Views: ${share.viewCount}');
}

// Revoke a share
await locationSharingService.revokeToken(token);
```

## Expiration and Cleanup

Share links expire automatically:

* Trip completion: Immediate expiration
* Time limit: 2 hours maximum
* Manual revocation: Anytime via app
* Trip cancellation: Immediate expiration

<Warning>
  After expiration, the share link will show "This trip has ended" and no longer display location data.
</Warning>

## Technical Implementation

### Database Schema

```sql theme={null}
CREATE TABLE location_shares (
  id INT PRIMARY KEY AUTO_INCREMENT,
  token VARCHAR(255) UNIQUE NOT NULL,
  trip_id INT NOT NULL,
  user_id INT NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  expires_at TIMESTAMP NOT NULL,
  view_count INT DEFAULT 0,
  last_viewed_at TIMESTAMP,
  active BOOLEAN DEFAULT TRUE,
  FOREIGN KEY (trip_id) REFERENCES viajes(id),
  FOREIGN KEY (user_id) REFERENCES users(id),
  INDEX idx_token (token),
  INDEX idx_trip (trip_id)
);
```

### API Endpoints

Location sharing uses these endpoints:

* `POST /location_sharing/create` - Generate share token
* `GET /location_sharing/{token}` - Get trip data for token
* `DELETE /location_sharing/{token}` - Revoke share
* `GET /location_sharing/active` - List user's active shares

See [Location Sharing API](/api/map/location-sharing) for details.

## Best Practices

<CardGroup cols={2}>
  <Card title="Share Selectively" icon="user-check">
    Only share with people you trust
  </Card>

  <Card title="Use for Safety" icon="shield-heart">
    Always share location for night trips
  </Card>

  <Card title="Verify Expiration" icon="hourglass">
    Check that links expire after trip
  </Card>

  <Card title="Test the Feature" icon="vial">
    Try sharing with yourself first
  </Card>
</CardGroup>

## Troubleshooting

<Accordion title="Share link not working">
  **Possible causes:**

  * Link expired
  * Trip cancelled
  * Network connectivity issue

  **Solutions:**

  * Generate a new share link
  * Verify trip is active
  * Check internet connection
</Accordion>

<Accordion title="Location not updating on share page">
  **Possible causes:**

  * GPS disabled on your device
  * App in background
  * Poor network signal

  **Solutions:**

  * Ensure GPS is enabled
  * Keep app in foreground during trip
  * Check your data connection
</Accordion>

<Accordion title="Can't create share link">
  **Possible causes:**

  * Trip not active
  * No internet connection
  * Backend service issue

  **Solutions:**

  * Ensure trip is in progress
  * Verify internet connectivity
  * Try again in a few moments
</Accordion>

## Future Enhancements

Planned improvements to location sharing:

* Multiple simultaneous shares
* Custom expiration times
* Share templates with pre-written messages
* Integration with emergency contacts
* Share history and analytics
* QR code generation for easy sharing

## Next Steps

<CardGroup cols={2}>
  <Card title="Trip Tracking" icon="map-location-dot" href="/users/trip-tracking">
    Learn about in-app trip tracking features
  </Card>

  <Card title="Safety Features" icon="shield">
    Explore other safety and security features
  </Card>
</CardGroup>

## Related Documentation

* [Location Sharing API](/api/map/location-sharing)
* [Trip Tracking](/users/trip-tracking)
* Privacy Policy
