Map Trix : Google Maps Interface
Description
This module provides an easy to use interface that allows to load and use Google Maps API.
Install
Available via npm as the package Map Trix.
npm install map-trix
Documentation and Usage
Load the lib and create an instance
import { createMapTrix } from 'map-trix'
// Google Maps lib options
const options = {
key: 'Your Google API Key',
language: 'en',
version: 'weekly',
libraries: ["places"]
/* TODO : to be completed */
}
/**
* Load the lib and create an instance
* @param {string} API_KEY : Your Google API Key @deprecated since version 1.4.4 please use options.key
* @param {object} options : { center: { lat: 0, lng: 0 }, zoom: 5 ... }
* @param {object} config : { enableBounds: false }
* @returns : MapTrix instance
*/
const mapTrix = await createMapTrix(API_KEY, options)
mapTrix.init('#YourMapElSelector')
Add marker
// Add marker without infoWindow
const point1 = {
latitude: 48.85840,
longitude: 2.29448
}
mapTrix.addMarker(point)
// Add marker with infoWindow
const point2 = {
latitude: 48.87574,
longitude: 2.29517,
content: 'infoWindow content'
}
mapTrix.addMarker(point2, true)
// Center map on loaded markers
mapTrix.boundsMarkers()
Create route between two points
/**
* @param {String|{latitude, longitude}} origin
* @param {String|{latitude, longitude}} destination
*/
mapTrix.traceDirection(point1, point2).then( successResponse => /* Your code here */ )
Load current location
import Utils from './utils/utils'
/**
* Load current user position
* @param {enableHighAccuracy = true, timeout = 5000, maximumAge = 0}
*/
Utils.getCurrentPosition().then( response => {
// Your code here...
// for example
mapTrix.addMarker({
latitude: response.coords.latitude,
longitude: response.coords.longitude,
content: 'My position'},
true
)
})