Socket
Socket
Sign inDemoInstall

g-mapify

Package Overview
Dependencies
0
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    g-mapify

Flexible react google map with more options of search, pick & select.


Version published
Weekly downloads
164
decreased by-21.9%
Maintainers
2
Created
Weekly downloads
 

Readme

Source

g-mapify NPM version Downloads All Contributors

Flexible react google map with more options of search, pick & select.

g-mapify

g-mapify

Getting Started

yarn add g-mapify

or

npm i g-mapify

Usage

Basic use:

    import  React from  'react';
    import { GMapify } from  'g-mapify';
    import  'g-mapify/dist/index.css';
    
    const  App = () => {
	    return (
		    <GMapify appKey="[google-map-key]" />
	    )
    }

Example: Basic map

basic map image

Example with options (Search Map)

import  React from  'react';
import { GMapify } from  'g-mapify';
import  'g-mapify/dist/index.css';

const  App = () => {
    const  onMapSelect = (status, data) => console.warn(status, data);
    
    return (
        <GMapify appKey="[google-map-key]" hasSearch onSelect={onMapSelect}/>
    )
}
Note

If status is getting false that means something happened bad on location search.

Map Search image

Example with multiple markers

import  React from  'react';
import { GMapify } from  'g-mapify';
import  'g-mapify/dist/index.css';

const  App = () => {

    const markers = [
        [28.4165425, 77.0437857, "Hello 1"],
        [28.415671, 77.0520993, `<div><h3>Southcity 2</h3> <img src="https://www.rentomojo.com/blog/wp-content/uploads/2019/07/shutterstock_1298400742.jpg" height="140"/> </div>`],
        [28.4175717, 77.05284840000002]
    ]

    const  onMapSelect = (status, data) => console.warn(status, data);
    
    return (
        <GMapify 
        appKey="[google-map-key]" 
        customMarkers={markers}
        autoCenter={false}
        onSelect={onMapSelect}/>
    )
}

Map Mutiple markers image

Options

PropsDescriptionDefault value
appKey (Mandatory)google map app keyIt's a mandatory value
latdefault latitude of map28.7041
lngdefault logitude of map77.1025
mapOptionsgoogle map options that you can change or add morezoom: 15, zoomControl: false, mapTypeControl: false, fullscreenControl: false, streetViewControl: false, clickableIcons: false, mapTypeId: "roadmap"
librariesadd more funcationality on google mapplaces
mapClassNamecustom class name for map elementNone
hasMarkershow marker in maptrue
markerIconmap marker iconBlue marker icon
autoCenterAuto center map on move or zoomtrue
customMarkersMultiple custom markers to mark on map[] (Example : [[lat, lng, content], [lat, lng, content], ...] )
allowSinglePopupAllow to open single popup on click custom markertrue
hasSearchapply search in mapfalse
mapSearchPlacemap search input box place (required a valid selector name like (#id, .class))bottom of the map
debounceTimesearch debounce time (unit ms)2000
inputClassNamecustom class name for Search inputNone
searchPlaceHolderplaceholder of search boxSearch here
searchClassNamecustom class name of search containerNone
onSelecttrigger whenever map position changed (return status: [true/false], data: [map data object], mapStatus: [map native status])
Note

When use customMarkers (More than 1) - Make sure autoCenter, hasSearch are set to false. Which dosen't make sense any way with multiple markers.

Using Ref (v2.3.0)

Support ref to access some functions directly.

    import  React from  'react';
    import { GMapify } from  'g-mapify';
    import  'g-mapify/dist/index.css';
    
    const  App = () => {
        const mapRef = useRef();

        const getLatLongByName = async () => {
            if (mapRef.current) {
                try {
                    const result = await mapRef.current.latLongFromQuery('BharatPe Office Delhi');
                    const lat = result[0]?.geometry.location.lat();
                    const lng = result[0]?.geometry.location.lng();
                } catch (e) {
                    // handle error
                }
            }
        };

	    return (
            <>
                <button onClick={getLatLongByName}>BharatPe Office Location</button>
                <GMapify ref={mapRef} appKey="[google-map-key]" />
            </>
	    )
    }

Functions are accessible directly:

FunctionDescriptionParametersReturn Value
latLongFromQueryGet Map data from address string without showing searchstringPromise<map data>

Address Formatter

You can get City, Pincode, State etc. from address_components using addressFormatter method. This method transfrom address_components array data into object.

import { GMapify, AddressFormatter } from  'g-mapify'

const  onMapSelect = (status, data) => {
    if (status) {
        console.warn('Map Data', data);
        
        // get formatted address from google map address_components
        const  formattedAddress = AddressFormatter(data.address_components);
        console.warn('formated address', formattedAddress);
    }
};

Refer example for all 3 map variations

Map variations image

Releases

Here Releases

Note: For Contributors

This repo build with create-react-library

Contributors

Here Contributors

License

ISC BharatPe TM

Keywords

FAQs

Last updated on 19 May 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc