{"id":27442998,"url":"https://github.com/0501guptanitin/typescript-geolocation-utils","last_synced_at":"2026-04-15T05:31:39.808Z","repository":{"id":287818035,"uuid":"965888002","full_name":"0501guptanitin/typescript-geolocation-utils","owner":"0501guptanitin","description":"A lightweight TypeScript utility to fetch user's geolocation (latitude, longitude, accuracy) using the browser's native Geolocation API. Simple, Promise-based, and ideal for modern frontend apps.","archived":false,"fork":false,"pushed_at":"2025-04-14T04:27:26.000Z","size":2,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-03T07:04:26.189Z","etag":null,"topics":["browser-api","coordinates","frontend","geolocation","javascript","latitude-and-longitude","location","navigator","nextjs","reactjs","typescript","utitlities"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0501guptanitin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-14T04:27:03.000Z","updated_at":"2025-04-14T04:30:02.000Z","dependencies_parsed_at":"2025-04-15T01:18:19.678Z","dependency_job_id":"d60b0ff3-5295-4f23-ab41-308a6ca9b0f8","html_url":"https://github.com/0501guptanitin/typescript-geolocation-utils","commit_stats":null,"previous_names":["0501guptanitin/typescript-geolocation-utils"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/0501guptanitin/typescript-geolocation-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0501guptanitin%2Ftypescript-geolocation-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0501guptanitin%2Ftypescript-geolocation-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0501guptanitin%2Ftypescript-geolocation-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0501guptanitin%2Ftypescript-geolocation-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0501guptanitin","download_url":"https://codeload.github.com/0501guptanitin/typescript-geolocation-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0501guptanitin%2Ftypescript-geolocation-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31828530,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T18:05:02.291Z","status":"online","status_checked_at":"2026-04-15T02:00:06.175Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser-api","coordinates","frontend","geolocation","javascript","latitude-and-longitude","location","navigator","nextjs","reactjs","typescript","utitlities"],"created_at":"2025-04-15T01:18:18.222Z","updated_at":"2026-04-15T05:31:39.784Z","avatar_url":"https://github.com/0501guptanitin.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📍 Get Geolocation Data in the Browser (TypeScript Utility)\n\nThis utility provides a simple, Promise-based way to access the user's geolocation in the browser using the **Geolocation API**, written in **TypeScript**.\n\n---\n\n## ✨ Features\n\n- ✅ Promise-based API\n- 🌐 Retrieves `latitude`, `longitude`, and `accuracy`\n- 🔐 Graceful fallback if geolocation is not supported\n- ⚙️ Customizable options like high accuracy, timeout, and max age\n\n---\n\n## 📦 Usage\n\n### 1. Import and Call the Function\n\n```ts\nimport { getGeolocationData } from './utils/geolocation';\n\ngetGeolocationData()\n  .then((location) =\u003e {\n    console.log('Location data:', location);\n  })\n  .catch((error) =\u003e {\n    console.error('Geolocation error:', error.message);\n  });\n```\n\n---\n\n## 🔍 Full Source Code\n\n```ts\ninterface GeolocationResponse {\n    latitude: number;\n    longitude: number;\n    accuracy: number;\n}\n\nexport const getGeolocationData = (): Promise\u003cGeolocationResponse\u003e =\u003e {\n    return new Promise((resolve, reject) =\u003e {\n        if (\"geolocation\" in navigator) {\n            navigator.geolocation.getCurrentPosition(\n                (position) =\u003e {\n                    const locationData: GeolocationResponse = {\n                        latitude: position.coords.latitude,\n                        longitude: position.coords.longitude,\n                        accuracy: position.coords.accuracy\n                    };\n                    resolve(locationData);\n                },\n                (error) =\u003e {\n                    reject(new Error(`Geolocation error: ${error.message}`));\n                },\n                {\n                    enableHighAccuracy: true,\n                    timeout: 5000,\n                    maximumAge: 0\n                }\n            );\n        } else {\n            reject(new Error(\"Geolocation is not supported by this browser.\"));\n        }\n    });\n}\n```\n\n---\n\n## 🚫 Fallback Handling\n\nIf the browser does **not support** geolocation, the promise is rejected with a clear error message:\n\n\u003e \"Geolocation is not supported by this browser.\"\n\n---\n\n## 🔐 Permissions\n\nModern browsers require users to grant **explicit permission** to access location. Make sure you handle rejections gracefully in your app.\n\n---\n\n## 🗂️ File Structure\n\nYou can place the utility like this:\n\n```\nsrc/\n└── utils/\n    └── geolocation.ts\n```\n\n---\n\n## 📝 License\n\nMIT — feel free to use, modify, and contribute!\n\n---\n\n\u003e 🌍 Accurate user location with a simple Promise — great for maps, weather, or personalized experiences.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0501guptanitin%2Ftypescript-geolocation-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0501guptanitin%2Ftypescript-geolocation-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0501guptanitin%2Ftypescript-geolocation-utils/lists"}