0.1.1 • Published 5 years ago

jw-google-map v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

jw-google-map

A react component for google map.

NPM version build status node version npm download

Demo

Install

NPM

Static Methods

MethodParametersDescription
setAPIKeyapi: string.set the API key for google map and reload the Map API script.

Methods

MethodParametersDescription
getMapCenterretrieve the lat and long of the center of the map view.
setMarkerposition: object consist of{ lat: number, lng: number }.set a marker on a given position of map.

Props

PropDescription
center(optional)the initial center of the map. Default: { lat: 0, lng: 0 }
zoom(optional)the initial zoom of the map. Default: 0

Usage

import React, { Component } from "react";
import ReactDOM from "react-dom";
import Map, { setAPIKey } from "jw-google-map";

import "./style.css";

class Demo extends Component {
  conponentDidMount() {
    setAPIKey(`<API KEY HERE>`);

    const { map } = this;

    const position = map.getMapCenter();

    map.setMarker(position);
  }

  render() {
    return <Map ref={m => (this.map = m)} />;
  }
}

ReactDOM.render(<Demo />, document.getElementById("root"));