jw-google-map
v0.1.1
Published
A react component for google map.
Downloads
1
Readme
jw-google-map
A react component for google map.
Install
Static Methods
| Method | Parameters | Description |
| ----------- | -------------- | ------------------------------------------------------------- |
| setAPIKey
| api
: string. | set the API key for google map and reload the Map API script. |
Methods
| Method | Parameters | Description |
| -------------- | ------------------------------------------------------------------- | -------------------------------------------------------- |
| getMapCenter
| | retrieve the lat and long of the center of the map view. |
| setMarker
| position
: object consist of{ lat
: number, lng
: number }. | set a marker on a given position of map. |
Props
| Prop | Description |
| ------------------ | ------------------------------------------------------------ |
| 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"));