# static-google-map-ts

> A strongly typed URL builder for Google Maps Static.

Latest version **0.0.9** (published 2022-06-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install static-google-map-ts
pnpm add static-google-map-ts
yarn add static-google-map-ts
bun add static-google-map-ts
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2022-06-09 |
| First published | 2022-06-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 46 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | John Bayly |
| Maintainers | john.bayly |

## Links

- npm: https://www.npmjs.com/package/static-google-map-ts
- Repository: https://github.com/tipstrade/static-google-map-ts
- Homepage: https://github.com/tipstrade/static-google-map-ts#readme
- Issues: https://github.com/tipstrade/static-google-map-ts/issues
- npm.io page: https://npm.io/package/static-google-map-ts

## Recent versions

- 0.0.9 (latest) — 2022-06-09

## README

# static-google-map-ts

A strongly typed URL builder for Google Maps Static.

# Overview

This is designed to be [mostly] compatible with the [static-google-map](https://github.com/DaddyWarbucks/static-google-map) package, but is written
entirely in TypeScript. To reduce dependencies, it doesn't have implement asynchronous `asyncStaticMapUrl` method, however it supports
[Encoded Polyline Algorithm Format](https://developers.google.com/maps/documentation/utilities/polylinealgorithm). See [Paths](#paths)

## Installation

```
npm install static-google-map-ts
```

## Basic Usage

```ts
import { staticMapUrl, GoogleMapImage } from "static-google-map-ts";

const options: GoogleMapImage = {
  key: "Your API Key",
  size: {width: 600, height: 600}, // Also accepts a string, eg. "600x600"
  zoom: 8,
  markers: {
    location: "TipsTrade,GBR", // Also accepts a google.maps.LatLng or google.maps.LatLngLiteral
},
const url = staticMapUrl(options);
```

## Reference

Documentation isn't unavailable yet, however the properties usage is described in the [Maps Static API Documentation](https://developers.google.com/maps/documentation/maps-static/start#introduction). JSDoc comments are also provided for all types and interfaces.

### Parameter types

Most properties should be self explanatory, however some are Union types:

- `AnchorType` - Can be any of the following
- * a string containing an [anchor](https://developers.google.com/maps/documentation/maps-static/start#CustomIcons) ("left", "top", etc)
- * a string containing an x,y point ("16, 21")
- * an `Anchor` interface `{x:16, y:21}`
- `ColorType` - Can be any of the following
- * a string from the [set of colors](https://developers.google.com/maps/documentation/maps-static/start#PathStyles) ("black", "brown" etc)
- * a 24-bit RGB ("0xaabbcc") or 32-bit RGBA ("0xaabbccff") hex string
- * a number
- `LocationType` - Can be any of the following
- * a string cotnaining a place
- * a string containing a position, ("51.75, -1")
- * a `LatLng` interface, as used by the Google Maps API
- * a `LatLngLiteral` interface, as used by the Google Maps API
- `SizeType` - Can be any of the following
- * a string containing a size ("600x400")
- * a `Size` interface `{width: 600, height: 400}`

### Paths

The `Path` interface accepts both an array of `LocationType` objects or a string containing [Encoded Polyline Algorithm Format](https://developers.google.com/maps/documentation/utilities/polylinealgorithm). 

#### Usage alongside the Google Directions API

``` ts
new google.maps.DirectionsService().route({
  origin: "Dublin",
  destination: "Limerick",
  travelMode: google.maps.TravelMode.DRIVING,
}, (result, status) => {
  if (!result || status !== google.maps.DirectionsStatus.OK) {
    return;
  }

  // The overview_polyline contains a simplified route path and is already encoded
  const points = result.routes[0].overview_polyline;

  const url = staticMapUrl({
    key: "Your API Key",
    size: {width: 600, height: 400},
    paths: {
      points,
    },
  })

  console.log(url);
});
```

---
_Source: https://npm.io/package/static-google-map-ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
