Coder Social home page Coder Social logo

kashaudhan / react-gmap-picker Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 4.01 MB

React google maps location picker/marker (latitude, longitude)

Home Page: https://www.npmjs.com/package/react-gmap-picker

License: MIT License

TypeScript 88.55% CSS 5.97% HTML 5.48%
googe-map map-marker react

react-gmap-picker's Introduction

react-gmap-picker

React google maps location picker/marker with Advanced Marker

Table of Contents

Installation

Install react-gmap-picker and its dependeices

npm install --save react-gmap-picker

or

yarn add react-gmap-picker

Usage/Examples

import { useState } from 'react';
import { Picker } from 'react-gmap-picker';
import React from 'react';

const INITIAL_LOCATION = { lat: 13.4, lng: 77.0 };
const INITIAL_ZOOM = 10;

const API_KEY = process.env.API_KEY as string;

const App = () => {
  const [defaultLocation, setDefaultLocation] = useState(INITIAL_LOCATION);
  const [location, setLocation] = useState(defaultLocation);
  const [zoom, setZoom] = useState(INITIAL_ZOOM);

  const handleChangeLocation = (lat: number, lng: number) => {
    setLocation({ lat, lng });
  };

  const handleChangeZoom = (newZoom: number) => {
    setZoom(newZoom);
  };

  const handleResetLocation = () => {
    setDefaultLocation({ ...INITIAL_LOCATION });
    setLocation({ ...INITIAL_LOCATION });
    setZoom(INITIAL_ZOOM);
  };

  return (
    <div>
      <button onClick={handleResetLocation}>Reset Location</button>
      <label>Latitude:</label>
      <input type="text" value={location.lat} disabled />
      <label>Longitude:</label>
      <input type="text" value={location.lng} disabled />
      <label>Zoom:</label>
      <input type="text" value={zoom} disabled />

      <div>
        <h4>Map 1 (roadmap)</h4>
        <Picker
          defaultLocation={defaultLocation}
          zoom={zoom}
          mapTypeId="roadmap"
          style={{ height: '700px' }}
          onChangeLocation={handleChangeLocation}
          onChangeZoom={handleChangeZoom}
          apiKey={API_KEY}
        />
      </div>
    </div>
  );
};

export default App;

Props

Parameter Type Default Description
apiKey string Required Required. Google maps API key
defaultLocation {lat: number; lng: number} Required Required. Default coordinate.
zoom {lat: number; lng: number} 7 Default coordinate.
onChangeLocation (lat: number, lng: number) => void null Executes when location changes.
onChangeZoom (zoom: number) => void null Executes when room level changes.
style any { width: '100%', height: '600px' } Map container style.
className string undefined Map className.
mapTypeId google.maps.MapTypeId undefined Map type you want to see.

react-gmap-picker's People

Contributors

kashaudhan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.