{"id":21106439,"url":"https://github.com/igorpreston/ember-cli-geo","last_synced_at":"2025-05-17T09:40:51.673Z","repository":{"id":34552662,"uuid":"38497654","full_name":"igorpreston/ember-cli-geo","owner":"igorpreston","description":"Geolocation service for Ember.js web apps","archived":false,"fork":false,"pushed_at":"2022-12-08T17:59:08.000Z","size":1700,"stargazers_count":49,"open_issues_count":31,"forks_count":16,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-30T00:47:40.300Z","etag":null,"topics":["ember","ember-cli","ember-cli-addon","geolocation","html5-geolocation-api"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/igorpreston.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-03T14:50:12.000Z","updated_at":"2024-01-25T09:51:05.000Z","dependencies_parsed_at":"2023-01-15T07:45:15.784Z","dependency_job_id":null,"html_url":"https://github.com/igorpreston/ember-cli-geo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorpreston%2Fember-cli-geo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorpreston%2Fember-cli-geo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorpreston%2Fember-cli-geo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorpreston%2Fember-cli-geo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igorpreston","download_url":"https://codeload.github.com/igorpreston/ember-cli-geo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225228045,"owners_count":17441035,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["ember","ember-cli","ember-cli-addon","geolocation","html5-geolocation-api"],"created_at":"2024-11-20T00:26:25.348Z","updated_at":"2024-11-20T00:26:25.936Z","avatar_url":"https://github.com/igorpreston.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ember-cli-geo\n[![Code Climate](https://codeclimate.com/github/igorpreston/ember-cli-geo/badges/gpa.svg)](https://codeclimate.com/github/igorpreston/ember-cli-geo) [![Build Status](https://travis-ci.org/igorpreston/ember-cli-geo.svg)](https://travis-ci.org/igorpreston/ember-cli-geo)\n\nThis addon is a go-to solution for integrating HTML5 Geolocation API into your Ember.js web app.\nIt is production-ready and backwards compatible.\n\n## Installation\n\n```\nember install ember-cli-geo\n```\n\n## Usage\n#### getLocation()\n`getLocation()` gets user location from the browser and writes its coordinates to `currentLocation` property on the service. Accepts __geoOptions__ as an argument. Returns an __Ember.RSVP.Promise__ which is either resolved with __geoObject__ containing all data about user location or is rejected with __reason__ which explains why geolocation failed.\nIt is used like this:\n```js\nthis.get('geolocation').getLocation().then(function(geoObject) {\n  // do anything with geoObject here\n  // you can also access currentLocation property and manipulate its data however you like\n});\n```\nIt corresponds to _getCurrentPosition() in HTML5 Geolocation API_. Learn more at [getCurentPosition() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition).\nIt emits an event `geolocationSuccess` with an object describing the geolocation when the position is available. If it fails, it emits an event `geolocationFail` with a reason.\n#### trackLocation()\n`trackLocation()` gets user location and setups a watcher which observes any changes occuring to user location. It then constantly updates `currentLocation` with the most recent location coordinates.\n\nIt accepts __geoOptions__ as an argument. Returns an __Ember.RSVP.Promise__ which is either resolved with __geoObject__ containing all data about user location or is rejected with __reason__ which explains why geolocation failed.\nIt accepts an optional __callback__ function, that is called whenever the position is updated.\nIt emits an event `geolocationSuccess` with an object describing the geolocation whenever a new position is available. If it fails, it emits an event `geolocationFail` with a reason.\n\nIt is used like this:\n```js\nthis.get('geolocation').trackLocation().then(function(geoObject) {\n  // do anything with geoObject here\n  // currentLocation is constantly updated if user location is changed\n});\n// or\nthis.get('geolocation').trackLocation(null, (geoObject) =\u003e { /* will be called with new positiond */ })\n// or\nconst service = this.get('geolocation');\nservice.on('geolocationSuccess', (geoObject) =\u003e { { /* will be called with new position */);\n```\nIt corresponds to _watchPosition() in HTML5 Geolocation API_. Learn more at [watchPosition() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition).\n#### stopTracking\n`stopTracking()` stops the app from continuously updating the user location.\n\nIt accepts an optional boolean parameter that clears `currentLocation` if it's true.\n\nIt is used like this:\n```js\nthis.get('geolocation').stopTracking(true);\n```\nIt corresponds to _watchPosition() in HTML5 Geolocation API_. Learn more at [clearWatch() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/clearWatch).\n#### currentLocation\n`currentLocation` is a property of geolocation service which stores the __array__ of user location coordinates in the format of __[lat, lon]__.\nIt is used like this:\n```js\nthis.get('geolocation').get('currentLocation');\n```\n#### geoObject\n`geoObject` is an object which contains all data about user location. Both `getLocation()` and `trackLocation()` promises are resolved with it. It looks like this:\n```js\n{\n  coords: {\n    accuracy: 100,\n    altitude: 0,\n    altitudeAccuracy: 0,\n    heading: NaN,\n    latitude: 37.789,\n    longitude: -122.412,\n    speed: NaN\n  },\n  timestamp: 1435861233751\n}\n```\nIt corresponds to _Position object in HTML5 Geolocation API_. Learn more at [Position object on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Position).\n#### reason\n`reason` is an error object which contains data about why geolocation has failed. Both `getLocation()` and `trackLocation()` promises are rejected with it.\nIt corresponds to _PositionError object in HTML5 Geolocation API_. Learn more at [PositionError object on MDN](https://developer.mozilla.org/en-US/docs/Web/API/PositionError).\n#### geoOptions\n`geoOptions` is an optional object that can be passed to both `getLocation()` and `trackLocation()` to customize geolocation query. If you didn't pass it to functions, then next defaults will be automatically passed:\n```js\n{\n  enableHighAccuracy: false,\n  timeout: Infinity,\n  maximumAge: 0\n}\n```\nIt corresponds to _PositionOptions object in HMTL5 Geolocation API_. Learn more at [PositionOptions object on MDN](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).\n### Usage Examples\n\n#### Setup geolocation service\nIn order to use geolocation inside of your _Ember.Route_ you should directly inject it to the one:\n```js\nexport default Ember.Route.extend({\n  geolocation: Ember.inject.service()\n});\n```\n\n#### Get user location and display it in your template\nYou need to implement a custom action which will call the geolocation service.\nIn your route:\n```js\n// app/routes/geolocator.js\n\nexport default Ember.Route.extend({\n\n  actions: {\n    getUserLocation: function() {\n      this.get('geolocation').getLocation().then(function(geoObject) {\n        var currentLocation = this.get('geolocation').get('currentLocation');\n        this.controllerFor('geolocator').set('userLocation', currentLocation);\n      });\n    }\n  }\n});\n```\n\nIn your controller:\n```js\n// app/controllers/geolocator.js\n\nexport default Ember.Controller.extend({\n  userLocation: null\n});\n```\n\nIn your template:\n```js\n// app/templates/geolocator.hbs\n\n\u003cbutton type=\"button\" {{action 'getUserLocation'}}\u003eGeolocate me!\u003c/button\u003e\n{{#if userLocation}}\n  {{userLocation}}\n{{/if}}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorpreston%2Fember-cli-geo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figorpreston%2Fember-cli-geo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorpreston%2Fember-cli-geo/lists"}