gmaps-url-coords
v1.0.2
Published
Universal zero-dependency parser & resolver to extract coordinates(latitude, longitude) and place details from any google maps URL or short link.
Maintainers
Readme
gmaps-url-coords
Universal, zero-dependency parser and resolver to extract coordinates (latitude, longitude) from Google Maps short links (maps.app.goo.gl and goo.gl/maps).
Features
- Zero External Dependencies: Ultra-lightweight bundle size (< 3 KB).
- Isomorphic / Universal: Works seamlessly in Browser, Node.js, Bun, Deno, and Next.js.
- Short Link Resolution: Resolves maps.app.goo.gl and goo.gl/maps short links.
- TypeScript First: Full auto-generated .d.ts types and TSDoc autocompletion.
Installation
pnpm add gmaps-url-coords
# or
npm install gmaps-url-coords
# or
bun add gmaps-url-coordsUsage
import { isShortLink, resolveShortLink } from "gmaps-url-coords";
// 1. Check if a URL is a Google Maps short link
isShortLink("https://maps.app.goo.gl/o7r7NdfotKNF2Yb59"); // returns true
// 2. Resolve short link to coordinates
const result = await resolveShortLink("https://maps.app.goo.gl/o7r7NdfotKNF2Yb59");
console.log(result.latitude); // "27.684214"
console.log(result.longitude); // "85.353472"API Reference
Functions
| Function | Returns | Description |
| ----------------------- | ----------------------------- | --------------------------------------------------------------- |
| isShortLink(url) | boolean | Checks if a URL is a Google Maps short link (maps.app.goo.gl) |
| resolveShortLink(url) | Promise<MapsLocationResult> | Resolves a short link to latitude and longitude |
Return Object (MapsLocationResult)
| Property | Type | Description |
| ------------- | --------------------- | ------------------------------ |
| latitude | string \| null | Extracted latitude coordinate |
| longitude | string \| null | Extracted longitude coordinate |
| isShortLink | boolean | true for short links |
| resolvedUrl | string \| undefined | Expanded target URL |
| originalUrl | string | Original input URL |
License
MIT © Dinesh Basnet
