2.0.2 • Published 4 years ago

map-google-react v2.0.2

Weekly downloads
13
License
MIT
Repository
github
Last release
4 years ago

map-google-react

A highly customizable Google Map component which exposes complete customization options. It uses Google's Places API for Autocomplete options and fetching the details of a location. It also uses the Geococoder API to get the details of a coordinate. SearchBox component is exported which can be used as a child of GoogleMap component to make it customizable and controllable separately.

Installation

Use the package manager yarn to install map-google-react.

yarn add map-google-react

or using npm

npm install map-google-react

Usage

import { GoogleMap, SearchBox } from 'map-google-react';
<GoogleMap
    googleMapUrl={`https://maps.googleapis.com/maps/api/js?key=<MAP_API_KEY>&libraries=places,geocoder`}
>
    <SearchBox />
</GoogleMap>

Props

GoogleMap

PropTypeDefaultDescription
googleMapUrlstring-Google map url with API key. (libraries needed: places & geocoder) Ex: https://maps.googleapis.com/maps/api/js?key=<MAP_API_KEY>&libraries=places,geocoder
markerIconUrlstringhttps://maps.gstatic.com/mapfiles/api-3/images/spotlight-poi2_hdpi.pngUrl for the marker icon. Image located on the url should be of expected size of the marker.
defaultCenter{ lat: number; lng: number }{ lat: 26.850000, lng: 80.949997 }Default center for the map when it is loaded
defaultMarker{ lat: number; lng: number }-Default marker to be diplayed on map when it is loaded. This overrides defaultCenter prop.
defaultZoomnumber (0 - 18)14Default zoom factor for the google map
mapOptionsgoogle.maps.MapOptions{ mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false, streetViewControl: false, fullscreenControl: false, scaleControl: false, zoomControl: true, disableDoubleClickZoom: true, clickableIcons: false }Fields array accepted by Google maps Places API. This is going to save your cost. :D
placesOptionsArray'geometry', 'formatted_address'Fields array accepted by Google maps Places API. This is going to save your cost. :D
markerOptionsgoogle.maps.ReadonlyMarkerOptions-Marker options to customize marker. (Note: markerIconUrl has precedence over the icon prop here)
infoWindowLoaderJSX.Element-Loader to show inside info window till the details are loaded
infoWindowstring<div style="display: flex; flex-direction: column; justify-content: center; font-size: 0.918rem; min-height: 28px;"><b>mainText</b>secondaryText</div>Stringified element for Info Window with mainText and secondaryText in place. These keywords are replaced with actual values.
beforeChange() => void-Gets called before the change starts. In case you need to disable any confirm button in place till new location is selected.
onPlacesChange(coordinates: { key: string: number }, callback: (place: string) => void) => void;-Receives the coordinates { lat, lng } and then expects user to do callback with the location text separated by hyphen (-). eg: 'Para - Lucknow'. This is helpful when we fetch the location from coordinates on our own server to create a database, and then pass that to callback so next time for a same request we don't need to fetch details from google. This will bypass the Geocoder API and more savings. :D
afterChange(data: { lat: number, lng: number, place: string }) => void-Gets called once map is finished updating and returns the final lat, lng and the location text
onError(error: any) => void-Gets called an error is ocurred

SearchBox

PropTypeDefaultDescription
placeholderstring'Search location'Placeholder for the search input
inputStylesCSSProperties-Custom styles for the input element
suggestionStylesCSSProperties-Custom styles for a single suggestion in autocomplete
searchOptionsgoogle.maps.places.AutocompletionRequest-Custom options for the AutoComplete API

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago