@capacitor/core#GeolocationPosition TypeScript Examples

The following examples show how to use @capacitor/core#GeolocationPosition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: geolocation.service.ts    From mylog14 with GNU General Public License v3.0 6 votes vote down vote up
getPosition(useCache = true): Observable<GeolocationPosition> {
    const cache = (this.isCachedPositionValid() && useCache);
    const position$ = (cache) ? of(this.cachedPosition) : from(Geolocation.getCurrentPosition(this.defaultGeolocationOptions));
    return position$
      .pipe(
        take(1),
        map(position => {
          console.log('Geolocation retrieved', position);
          this.cachedPositionTime = Date.now();
          return this.cachedPosition = position;
        }),
      );
  }
Example #2
Source File: proof.service.ts    From mylog14 with GNU General Public License v3.0 6 votes vote down vote up
/** WORKAROUND:
   * For some unknown reason neither Object.assign() nor spread syntax works on copying the geoposition
   *  manually copy each property of the GeolocationPosition
   */
  private getLocationProof(position: GeolocationPosition): LocationProof {
    return {
      latitude: position.coords.latitude,
      longitude: position.coords.longitude,
      accuracy: position.coords.accuracy,
      altitude: position.coords.altitude,
      altitudeAccuracy: position.coords.altitudeAccuracy,
      heading: position.coords.heading,
      speed: position.coords.speed,
    } as LocationProof;
  }
Example #3
Source File: geolocation.service.ts    From mylog14 with GNU General Public License v3.0 5 votes vote down vote up
cachedPosition: GeolocationPosition;