Follow Position
This example demonstrates how to track and follow the user's real-time location on the map with smooth camera animations.
Live Demo
Overview
The example highlights the following features:
- Requesting location permissions
- Setting up live position tracking
- Following user's position with camera
- Smooth camera animations
Code Implementation
Initialize Map
Follow Position Function
Create Follow Button
Utility Function
Key Features
- Location Permission: Automatically requests browser location permission
- Live Data Source: Sets up continuous position updates from device GPS
- Camera Animation: Smooth transitions when following position
- Single Initialization: Live data source is set only once for efficiency
Browser Permissions
The browser will prompt for location permission when you click "Follow Position":
- Allow: Map will track and follow your real-time location
- Deny: Feature will not work (message displayed)
HTTPS Required
Most browsers require HTTPS to access location services. Make sure your app is served over HTTPS in production.
Animation Types
The SDK supports the following animation types:
AnimationType.none: No animation (instant movement)AnimationType.linear: Smooth linear movement
You can also set a custom duration in milliseconds when creating the animation:
const animation = new GemAnimation({
type: AnimationType.linear,
duration: 2000 // 2 seconds
});
Next Steps
- Center Coordinates - Manually center the map
- Map Perspective - Control camera angle