Installation
Prerequisites
Before installing Route Optimization Map, ensure you have:
- Node.js 18.0 or higher
- npm, pnpm, or yarn package manager
- A Google Maps API key (Get one here)
Package Selection
Choose the package(s) that match your tech stack:
| Package | Use When | Dependencies |
|---|---|---|
@route-optimization/react | Building with React | Requires react, react-dom |
@route-optimization/vue | Building with Vue 3 | Requires vue 3.3+ |
@route-optimization/vanilla | Vanilla JS or other frameworks | No framework dependencies |
@route-optimization/core | Using with unlisted framework | No framework dependencies |
@route-optimization/converter | Converting DirectionsResult | No dependencies |
Installation Commands
React
bash
npm install @route-optimization/react @route-optimization/corebash
pnpm add @route-optimization/react @route-optimization/corebash
yarn add @route-optimization/react @route-optimization/coreVue 3
bash
npm install @route-optimization/vue @route-optimization/corebash
pnpm add @route-optimization/vue @route-optimization/corebash
yarn add @route-optimization/vue @route-optimization/coreVanilla JavaScript
bash
npm install @route-optimization/vanillabash
pnpm add @route-optimization/vanillabash
yarn add @route-optimization/vanillaConverter Only
bash
npm install @route-optimization/converter @route-optimization/corebash
pnpm add @route-optimization/converter @route-optimization/corebash
yarn add @route-optimization/converter @route-optimization/coreTypeScript Configuration
If using TypeScript, ensure your tsconfig.json includes:
json
{
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020", "DOM"],
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}Google Maps API Key
Get an API Key
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Maps JavaScript API
- Create credentials → API key
- (Optional) Restrict the key to your domain
Configure Environment Variables
env
REACT_APP_GOOGLE_MAPS_API_KEY=your_api_key_hereenv
VITE_GOOGLE_MAPS_API_KEY=your_api_key_hereenv
NEXT_PUBLIC_GOOGLE_MAPS_API_KEY=your_api_key_hereUse in Code
tsx
<RouteMapView apiKey={process.env.REACT_APP_GOOGLE_MAPS_API_KEY!} route={route} />vue
<RouteMapView :api-key="import.meta.env.VITE_GOOGLE_MAPS_API_KEY" :route="route" />javascript
const routeMap = new RouteMap({
apiKey: import.meta.env.VITE_GOOGLE_MAPS_API_KEY,
container: 'map',
});Verify Installation
Create a simple test to verify everything works:
typescript
import { RouteMapView } from '@route-optimization/react';
// or
import { RouteMapView } from '@route-optimization/vue';
// or
import { RouteMap } from '@route-optimization/vanilla';
console.log('✅ Package imported successfully!');Common Issues
Module Not Found
If you see "Module not found" errors:
- Clear cache:
rm -rf node_modules package-lock.json && npm install - Check versions: Ensure peer dependencies are installed
- Restart dev server
TypeScript Errors
If TypeScript doesn't recognize types:
- Check tsconfig.json: Ensure proper
moduleResolution - Restart TypeScript server: In VS Code,
Cmd/Ctrl + Shift + P→ "TypeScript: Restart TS Server" - Install type definitions:
npm install -D @types/google.maps
Google Maps Not Loading
If the map doesn't display:
- Check API key: Verify it's correct and enabled
- Check console: Look for error messages
- Verify billing: Ensure Google Cloud billing is enabled
- Check restrictions: Review API key restrictions