Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@trackcode/map

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trackcode/map

<!-- STORY -->

  • 3.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

@trackcode/map

A lightweight react package to interact with google maps.

npm install --save @trackcode/map
import React from "react";
import { Pin } from "@trackcode/map";

const MyMap = () => (
  <Map
    apiKey="YOU_API_KEY"
    libraries="places,geometry" // default "places"
    defaultZoom={14}
    defaultCenter={{ lat: 52.01525584, lng: 8.52046783 }}
  >
    <Pin label="A" position={{ lat: 52.02221556, lng: 8.53188536 }} />
  </Map>
);

Use script tag to load Google Maps

Add this script tag to the <head> of your website:

<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places"></script>

Example:

import React from "react";
import { Map, Pin, Driver } from "@trackcode/map";

const MyMap = () => (
  <div style={{ width: "350px", height: "400px" }}>
    <Map defaultZoom={14} defaultCenter={{ lat: 52.01525584, lng: 8.52046783 }}>
      <Pin label="A" position={{ lat: 52.02221556, lng: 8.53188536 }} />
      <Driver position={{ lat: 52.01757214, lng: 8.52521203 }} />
    </Map>
  </div>
);

<Map />

Important component to show the map.

Example

<Map
  defaultZoom={14}
  defaultCenter={{ lat: 52.01525584, lng: 8.52046783 }}
>

Properties

NameTypeDefaultDescription
apiKeystringGoogle Maps api key.
librariesstringplacesDefine libraries for Google Maps.
versionstringplacesUse specific Google Maps version.
childrenany@trackcode/map components e.g. <Pin />, <Driver />
defaultZoom *numberDefault zoom level
defaultCenter *objectDefault center
defaultCenter.latnumberLatitude
defaultCenter.lngnumberLongitude
defaultFullscreenControlbooleantrueThe display options for the Fullscreen control.
defaultMapTypeControlbooleantrueThe initial enabled/disabled state of the Map type control.
defaultStreetViewControlbooleantrueThe initial enabled/disabled state of the Street View Pegman control.
defaultZoomControlbooleantrueThe enabled/disabled state of the Zoom control.

* required

<Pin />

A pin (or marker) to show a location on the map.

Example

<Pin
  appearance="subtle"
  position={{ lat: 52.0277157, lng: 8.50419146 }}
/>
<Pin position={{ lat: 52.0287157, lng: 8.52419146 }} />
<Pin label="A" position={{ lat: 52.0287157, lng: 8.54419146 }} />

Properties

NameTypeDefaultDescription
appearancestring"primary"The base styling to apply to the Pin. Possible values are "primary", "subtle".
position *ObjectSet position
position.latnumberLatitude
position.lngnumberLongitude
labelstringSet label
onClickfunctionHandle click event.

* required

<Driver />

Show a driver point on map. This component is able to animate position changes in a smooth way.

Example

<Driver position={{ lat: 52.0287157, lng: 8.52419146 }} />
<Driver active={false} title="Inactive" position={{ lat: 52.0287157, lng: 8.53419146 }} />

Properties

NameTypeDefaultDescription
position *ObjectSet position
position.latnumberLatitude
position.lngnumberLongitude
titlestringShow a title tooltip
activebooleantrueBlur color for active and gray if it's inactive

* required

<Directions />

Show directions on map.

Example

<Directions
  origin={{
    location: { lat: 52.012054, lng: 8.537375 },
  }}
  wayPoints={[{ location: "Herforder Straße 1, Bielefeld" }]}
  destination={{
    location: "Siegfriedstr. 18, Bielefeld",
  }}
/>

Properties

NameTypeDefaultDescription
origin *ObjectSettings for origin
origin.locationString | LatLngLocation of origin
destination *ObjectSettings for destination
destination.locationString | LatLngLocation of origin
wayPointsArrayWay points between origin and destination
wayPoints[].locationString | LatLngSettings of a way point
autoFitBoundsBooleantrueFit bounds based on direction path

Type: (Object) LatLng

NameTypeDescription
latnumberLatitude
lngnumberLongitude

* required

<Polygon />

Show polygon on map.

Example

<Polygon
  positions={[
    { lat: 52.01525584, lng: 8.52046783 },
    { lat: 52.02382442, lng: 8.52382776 },
    { lat: 52.02029969, lng: 8.53465948 },
    { lat: 52.00129969, lng: 8.53465948 },
    { lat: 52.01665505, lng: 8.55311308 },
    { lat: 52.0192433, lng: 8.55328474 },
  ]}
/>

Properties

NameTypeDefaultDescription
positions *ArrayList of LatLng positions.
positions[].latnumberLatitude
positions[].lngnumberLongitude
useConvexHullBooleantrueUse "convex hull" to draw outline polygon of a set of positions.

* required

Inspiration

  • react-google-maps, March 2018, https://github.com/tomchentw/react-google-maps
  • google-map-react, March 2018, https://github.com/google-map-react/google-map-react

FAQs

Package last updated on 21 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc