You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-google-maps-native

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-google-maps-native

TypeScript React components for Google Maps using native JS API with Marker, Path, and Cluster functionality

0.1.1
latest
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

React Google Maps Native

A lightweight TypeScript React library for integrating Google Maps into your application using the native Google Maps JavaScript API. This package provides ready-to-use components for creating maps, adding markers, drawing paths, and clustering markers without any external map package dependencies.

Installation

npm install react-google-maps-native

or

yarn add react-google-maps-native

Features

  • Written in TypeScript with full type definitions
  • No dependencies on other map libraries
  • Uses the native Google Maps JavaScript API directly
  • Provides React components for Maps, Markers, Paths, and Clusters
  • Proper cleanup of event listeners and DOM elements

Basic Usage

import { GoogleMap, Marker, Path, Cluster } from 'react-google-maps-native';

// Basic Map
const MapComponent = () => {
  return (
    <GoogleMap 
      apiKey="YOUR_GOOGLE_MAPS_API_KEY"
      center={{ lat: 37.7749, lng: -122.4194 }}
      zoom={12}
    />
  );
};

// Map with Markers
const MapWithMarkers = () => {
  return (
    <GoogleMap 
      apiKey="YOUR_GOOGLE_MAPS_API_KEY"
      center={{ lat: 37.7749, lng: -122.4194 }}
      zoom={12}
    >
      <Marker 
        position={{ lat: 37.7749, lng: -122.4194 }}
        title="San Francisco"
        infoWindowContent={<div>Welcome to San Francisco!</div>}
      />
      <Marker 
        position={{ lat: 37.7647, lng: -122.4321 }}
        title="Golden Gate Park"
      />
    </GoogleMap>
  );
};

// Map with Path
const MapWithPath = () => {
  const pathCoordinates = [
    { lat: 37.7749, lng: -122.4194 },
    { lat: 37.7647, lng: -122.4321 },
    { lat: 37.7837, lng: -122.4324 }
  ];

  return (
    <GoogleMap 
      apiKey="YOUR_GOOGLE_MAPS_API_KEY"
      center={{ lat: 37.7749, lng: -122.4194 }}
      zoom={12}
    >
      <Path 
        path={pathCoordinates}
        options={{
          strokeColor: '#0000FF',
          strokeOpacity: 0.8,
          strokeWeight: 3
        }}
      />
    </GoogleMap>
  );
};

// Map with Marker Clustering
const MapWithClusters = () => {
  const markers = [
    { id: 1, position: { lat: 37.7749, lng: -122.4194 }, title: "San Francisco" },
    { id: 2, position: { lat: 37.7647, lng: -122.4321 }, title: "Golden Gate Park" },
    { id: 3, position: { lat: 37.7837, lng: -122.4324 }, title: "Fisherman's Wharf" }
    // More markers...
  ];

  return (
    <GoogleMap 
      apiKey="YOUR_GOOGLE_MAPS_API_KEY"
      center={{ lat: 37.7749, lng: -122.4194 }}
      zoom={12}
    >
      <Cluster>
        {markers.map(marker => (
          <Marker 
            key={marker.id}
            position={marker.position}
            title={marker.title}
          />
        ))}
      </Cluster>
    </GoogleMap>
  );
};

API Reference

GoogleMap

Main component that renders a Google Map instance.

Props:

PropTypeDefaultDescription
apiKeystringrequiredYour Google Maps API key
centerLatLngLiteral{ lat: 0, lng: 0 }The initial center position of the map
zoomnumber10The initial zoom level of the map
optionsMapOptions{}Additional map options (see Google Maps API)
containerStyleCSSProperties{ width: '100%', height: '400px' }Style for the map container
onLoadfunction-Callback when map is loaded
onClickfunction-Callback when map is clicked
onDragEndfunction-Callback when map drag ends

Marker

Component for placing markers on the map.

Props:

PropTypeDefaultDescription
positionLatLngLiteralrequiredThe position of the marker (lat, lng)
iconstring/Icon/Symbol-Custom icon URL or object
labelstring/MarkerLabel-Marker label
titlestring-Marker title (shown on hover)
draggablebooleanfalseWhether the marker can be dragged
onClickfunction-Callback when marker is clicked
onDragEndfunction-Callback when marker drag ends
showInfoWindowbooleanfalseWhether to initially show the info window
infoWindowContentReactNode-Content for the info window
zIndexnumber-The zIndex of the marker

Path

Component for drawing lines on the map.

Props:

PropTypeDefaultDescription
pathLatLngLiteral[]requiredArray of positions (lat, lng)
optionsPolylineOptions{ strokeColor: '#FF0000', strokeOpacity: 1.0, strokeWeight: 2 }Path style options
onClickfunction-Callback when path is clicked
onMouseOverfunction-Callback when mouse enters path
onMouseOutfunction-Callback when mouse leaves path
editablebooleanfalseWhether the path is editable
draggablebooleanfalseWhether the path is draggable

Cluster

Component for clustering markers.

Props:

PropTypeDefaultDescription
optionsobject{}Clustering options
onClusteringBeginfunction-Callback when clustering begins
onClusteringEndfunction-Callback when clustering ends
onLoadfunction-Callback when clusterer is loaded

License

MIT

Keywords

react

FAQs

Package last updated on 24 Apr 2025

Did you know?

Socket

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