Skip to content

Commit f262088

Browse files
committed
API.md, TROUBLESHOOTING.md
1 parent de2901c commit f262088

File tree

2 files changed

+1201
-0
lines changed

2 files changed

+1201
-0
lines changed

react-native-meridian-maps/API.md

Lines changed: 365 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,365 @@
1+
# API Reference
2+
3+
This document provides detailed API reference for all components, interfaces, and methods available in react-native-meridian-maps.
4+
5+
## Table of Contents
6+
7+
- [Components](#components)
8+
- [MeridianMapView](#meridianmapview)
9+
- [Interfaces](#interfaces)
10+
- [MeridianMapViewProps](#meridianmapviewprops)
11+
- [MeridianMapViewComponentRef](#meridianmapviewcomponentref)
12+
- [MeridianMapsInterface](#meridianmapsinterface)
13+
- [Modules](#modules)
14+
- [MeridianMaps](#meridianmaps)
15+
- [Utility Functions](#utility-functions)
16+
- [isAvailable](#isavailable)
17+
- [Event Types](#event-types)
18+
- [Error Handling](#error-handling)
19+
20+
## Components
21+
22+
### MeridianMapView
23+
24+
The primary component for displaying Meridian indoor maps with real-time location tracking and navigation capabilities.
25+
26+
#### Usage
27+
28+
```typescript
29+
import { MeridianMapView } from 'react-native-meridian-maps';
30+
31+
<MeridianMapView
32+
appId="your-app-id"
33+
mapId="your-map-id"
34+
appToken="your-app-token"
35+
style={{ flex: 1 }}
36+
onMapLoadFinish={() => console.log('Map loaded')}
37+
/>
38+
```
39+
40+
#### Props
41+
42+
See [MeridianMapViewProps](#meridianmapviewprops) for detailed prop definitions.
43+
44+
#### Ref Methods
45+
46+
Access component methods using a ref:
47+
48+
```typescript
49+
const mapRef = useRef<MeridianMapViewComponentRef>(null);
50+
51+
// Trigger map update
52+
mapRef.current?.triggerUpdate();
53+
54+
// Start navigation to placemark
55+
mapRef.current?.startRoute('placemark-id');
56+
```
57+
58+
## Interfaces
59+
60+
### MeridianMapViewProps
61+
62+
```typescript
63+
interface MeridianMapViewProps {
64+
// Required Props
65+
appId: string; // Meridian application ID
66+
mapId: string; // Map identifier
67+
appToken: string; // Authentication token
68+
69+
// Optional Props
70+
style?: ViewStyle; // Component styling
71+
showLocationUpdates?: boolean; // Enable location tracking (default: true)
72+
73+
// Event Handlers
74+
onMapLoadStart?: () => void;
75+
onMapLoadFinish?: () => void;
76+
onMapLoadFail?: (error: ErrorEvent) => void;
77+
onLocationUpdated?: (location: LocationEvent) => void;
78+
onMarkerSelect?: (marker: MarkerEvent) => void;
79+
onMarkerDeselect?: (marker: MarkerEvent) => void;
80+
onMapTransformChange?: (transform: TransformEvent) => void;
81+
onOrientationUpdated?: (orientation: OrientationEvent) => void;
82+
onSearchActivityStarted?: (search: SearchEvent) => void;
83+
84+
// Navigation Events
85+
onDirectionsReroute?: (route: DirectionsEvent) => void;
86+
onDirectionsClick?: (directions: DirectionsEvent) => void;
87+
onDirectionsStart?: (directions: DirectionsEvent) => void;
88+
onRouteStepIndexChange?: (step: RouteStepEvent) => void;
89+
onDirectionsClosed?: () => void;
90+
onDirectionsError?: (error: DirectionsErrorEvent) => void;
91+
onUseAccessiblePathsChange?: (accessible: AccessibilityEvent) => void;
92+
onDirectionsCalculated?: (directions: DirectionsEvent) => void;
93+
onDirectionsRequestComplete?: (request: DirectionsRequestEvent) => void;
94+
onDirectionsRequestError?: (error: DirectionsRequestErrorEvent) => void;
95+
onDirectionsRequestCanceled?: () => void;
96+
97+
// Marker Events
98+
markerForSelectedMarker?: (marker: MarkerEvent) => void;
99+
onCalloutClick?: (callout: CalloutEvent) => void;
100+
101+
// Error Handling
102+
onError?: (error: ErrorEvent) => void;
103+
}
104+
```
105+
106+
### MeridianMapViewComponentRef
107+
108+
Interface for component ref methods:
109+
110+
```typescript
111+
interface MeridianMapViewComponentRef {
112+
/**
113+
* Trigger a manual update of the map component
114+
* Useful for refreshing the map after configuration changes
115+
*/
116+
triggerUpdate: () => void;
117+
118+
/**
119+
* Start navigation to a specific placemark
120+
* @param placemarkID - The unique identifier of the destination placemark
121+
*/
122+
startRoute: (placemarkID: string) => void;
123+
}
124+
```
125+
126+
### MeridianMapsInterface
127+
128+
Interface for the native module:
129+
130+
```typescript
131+
interface MeridianMapsInterface {
132+
/**
133+
* Open map in native activity/view controller
134+
* @param appId - Optional app ID override
135+
* @param mapId - Optional map ID override
136+
* @returns Promise resolving to operation result
137+
*/
138+
openMap(appId?: string, mapId?: string): Promise<string>;
139+
140+
/**
141+
* Open test activity for development/debugging
142+
* @returns Promise resolving to test result
143+
*/
144+
openTestActivity(): Promise<string>;
145+
}
146+
```
147+
148+
## Modules
149+
150+
### MeridianMaps
151+
152+
The native module providing low-level SDK functionality:
153+
154+
```typescript
155+
import { MeridianMaps } from 'react-native-meridian-maps';
156+
157+
// Open native map interface
158+
const result = await MeridianMaps.openMap('app-id', 'map-id');
159+
160+
// Open test interface
161+
const testResult = await MeridianMaps.openTestActivity();
162+
```
163+
164+
## Utility Functions
165+
166+
### isAvailable
167+
168+
Check if the Meridian SDK is properly installed and available:
169+
170+
```typescript
171+
import { isAvailable } from 'react-native-meridian-maps';
172+
173+
const checkSDK = async () => {
174+
try {
175+
const available = await isAvailable();
176+
if (available) {
177+
console.log('✅ Meridian SDK is ready');
178+
// Initialize your map
179+
} else {
180+
console.log('❌ Meridian SDK not available');
181+
// Show error message or fallback UI
182+
}
183+
} catch (error) {
184+
console.error('Error checking SDK:', error);
185+
}
186+
};
187+
```
188+
189+
#### Returns
190+
191+
- `Promise<boolean>` - `true` if SDK is available, `false` otherwise
192+
193+
#### What it checks
194+
195+
1. Native component registration in UIManager
196+
2. Native module availability
197+
3. Platform-specific SDK initialization
198+
4. View manager configuration
199+
200+
## Event Types
201+
202+
### LocationEvent
203+
204+
```typescript
205+
interface LocationEvent {
206+
latitude: number;
207+
longitude: number;
208+
accuracy?: number;
209+
floor?: number;
210+
building?: string;
211+
timestamp: number;
212+
}
213+
```
214+
215+
### MarkerEvent
216+
217+
```typescript
218+
interface MarkerEvent {
219+
id: string;
220+
name?: string;
221+
description?: string;
222+
latitude: number;
223+
longitude: number;
224+
floor?: number;
225+
category?: string;
226+
}
227+
```
228+
229+
### DirectionsEvent
230+
231+
```typescript
232+
interface DirectionsEvent {
233+
routeId: string;
234+
distance: number;
235+
duration: number;
236+
steps: RouteStep[];
237+
destination: MarkerEvent;
238+
}
239+
```
240+
241+
### ErrorEvent
242+
243+
```typescript
244+
interface ErrorEvent {
245+
code: string;
246+
message: string;
247+
details?: any;
248+
timestamp: number;
249+
}
250+
```
251+
252+
### TransformEvent
253+
254+
```typescript
255+
interface TransformEvent {
256+
zoom: number;
257+
center: {
258+
latitude: number;
259+
longitude: number;
260+
};
261+
bearing?: number;
262+
tilt?: number;
263+
}
264+
```
265+
266+
## Error Handling
267+
268+
### Common Error Codes
269+
270+
| Code | Description | Solution |
271+
|------|-------------|----------|
272+
| `SDK_NOT_AVAILABLE` | Meridian SDK not installed | Check installation and rebuild |
273+
| `INVALID_CREDENTIALS` | Invalid app ID, map ID, or token | Verify credentials |
274+
| `NETWORK_ERROR` | Network connectivity issues | Check internet connection |
275+
| `MAP_LOAD_FAILED` | Map failed to load | Check credentials and network |
276+
| `LOCATION_PERMISSION_DENIED` | Location permissions not granted | Request location permissions |
277+
| `NAVIGATION_ERROR` | Navigation/routing error | Check placemark ID and connectivity |
278+
| `FRAGMENT_MANAGER_ERROR` | Android FragmentManager transaction conflict | Delay map initialization or use proper lifecycle management |
279+
| `SDK_CONFIGURE_ERROR` | SDK configure() called multiple times | Implement native layer guards or App-level initialization |
280+
281+
282+
## Advanced Usage
283+
284+
### Custom Event Handling
285+
286+
```typescript
287+
const AdvancedMapExample = () => {
288+
const [mapState, setMapState] = useState({
289+
isLoaded: false,
290+
currentLocation: null,
291+
selectedMarker: null,
292+
isNavigating: false,
293+
});
294+
295+
const handleLocationUpdate = useCallback((location: LocationEvent) => {
296+
setMapState(prev => ({
297+
...prev,
298+
currentLocation: location
299+
}));
300+
301+
// Custom location processing
302+
if (location.accuracy && location.accuracy > 10) {
303+
console.warn('Low location accuracy:', location.accuracy);
304+
}
305+
}, []);
306+
307+
const handleMarkerInteraction = useCallback((marker: MarkerEvent) => {
308+
setMapState(prev => ({
309+
...prev,
310+
selectedMarker: marker
311+
}));
312+
313+
// Custom marker logic
314+
Analytics.track('marker_selected', {
315+
markerId: marker.id,
316+
markerName: marker.name
317+
});
318+
}, []);
319+
320+
return (
321+
<MeridianMapView
322+
// ... required props
323+
onLocationUpdated={handleLocationUpdate}
324+
onMarkerSelect={handleMarkerInteraction}
325+
onDirectionsStart={() => setMapState(prev => ({ ...prev, isNavigating: true }))}
326+
onDirectionsClosed={() => setMapState(prev => ({ ...prev, isNavigating: false }))}
327+
/>
328+
);
329+
};
330+
```
331+
332+
### Performance Optimization
333+
334+
```typescript
335+
const OptimizedMapView = memo(({ appId, mapId, appToken, ...otherProps }) => {
336+
// Memoize event handlers to prevent unnecessary re-renders
337+
const handleLocationUpdate = useCallback((location) => {
338+
// Throttle location updates if needed
339+
throttledLocationUpdate(location);
340+
}, []);
341+
342+
const handleMapTransformChange = useMemo(
343+
() => debounce((transform) => {
344+
// Handle transform changes with debouncing
345+
console.log('Map transform:', transform);
346+
}, 100),
347+
[]
348+
);
349+
350+
return (
351+
<MeridianMapView
352+
appId={appId}
353+
mapId={mapId}
354+
appToken={appToken}
355+
onLocationUpdated={handleLocationUpdate}
356+
onMapTransformChange={handleMapTransformChange}
357+
{...otherProps}
358+
/>
359+
);
360+
});
361+
```
362+
363+
---
364+
365+
For more examples and implementation details, see the [main README](README.md) and the [example app](example/src/App.tsx).

0 commit comments

Comments
 (0)