Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

google-current-geocode

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-current-geocode

Quick utility package to handle location permission and use current location to get complete location info using google places geocoding api.

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Google Current Geocode

A quick utility package to handle location permissions and retrieve complete location information using the Google Places Geocoding API.

This package is currently in the Beta Testing phase. We are testing it with the most commonly used libraries and frameworks while aiming to create frequently used location features. Feel free to contribute!

Easy to Set Up

  1. Install this lightweight package:
  npm install google-current-geocode
  1. Get your Google API key from Google Cloud Console

  2. Add the Google API script using the best approach for your project, or simply use the setupGooglePlacesApiScript function provided by the package:

import { setupGooglePlacesApiScript } from "google-current-geocode";
  1. Invoke the setup function in the most appropriate place based on your project.
// common usage
const googleApiKey = process.env.GOOGLE_API_KEY;
if(googleApiKey) setupGooglePlacesApiScript(googleApiKey);

// for React
useEffect(() => {
    const googleApiKey = process.env.REACT_APP_GOOGLE_API_KEY;
    if(googleApiKey) setupGooglePlacesApiScript(googleApiKey)
}, [])
  1. Call the location details fetcher function anywhere in your application. This simple function requests the user’s current location permission and calls the Google Geocoding API to fetch the location details.
import { getCurrentLocationDetails } from "google-current-geocode";

// common usage
document.querySelector("#location").addEventListener("click", () => getCurrentLocationDetails());

// for React
<button onClick={() => getCurrentLocationDetails()}>Get Location</button>
  1. Ensure type safety with @types/google.maps: The package utilizes the @types/google.maps package. If it does not work as expected, you can manually install the type definitions:
npm install @types/google.maps

Options & Customizations

You can pass options to customize the behavior of the getCurrentLocationDetails function:

getCurrentLocationDetails({ cache: true })
NameTypeDescription
cachebooleanAvoids calling the Google Geocoding API by caching location information based on latitude and longitude.

Contributor(s)

Keywords

FAQs

Package last updated on 16 Nov 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc