Skip to content

Commit e110b08

Browse files
committed
feat: add timestamp prop to the wrapped component
Adds support for the Geolocation API timestamp property and passes it to the wrapped component. Fixes #734
1 parent bc2e102 commit e110b08

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ The props passed to the wrapped component are:
8080
heading,
8181
speed,
8282
},
83+
timestamp, // timestamp of when the last position was retrieved
8384
isGeolocationAvailable, // boolean flag indicating that the browser supports the Geolocation API
8485
isGeolocationEnabled, // boolean flag indicating that the user has allowed the use of the Geolocation API
8586
positionError, // object with the error returned from the Geolocation API call
@@ -167,7 +168,7 @@ class Demo extends React.Component<IDemoProps & GeolocatedProps> {
167168
return (
168169
<div>
169170
label: {this.props.label}
170-
lattitude: {this.props.coords && this.props.coords.latitude}
171+
latitude: {this.props.coords && this.props.coords.latitude}
171172
</div>
172173
);
173174
}

index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ interface GeolocatedProps {
4343
* The Geolocation API's coords object containing latitude, longitude, and accuracy and also optionally containing altitude, altitudeAccuracy, heading and speed.
4444
*/
4545
coords?: Coordinates;
46+
/**
47+
* The Geolocation API's timestamp value representing the time at which the location was retrieved.
48+
*/
49+
timestamp?: DOMTimeStamp;
4650
/**
4751
* Flag indicating that the browser supports the Geolocation API.
4852
*/

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const geolocated = ({
2424

2525
state = {
2626
coords: null,
27+
timestamp: null,
2728
isGeolocationAvailable: Boolean(geolocationProvider),
2829
isGeolocationEnabled: isOptimisticGeolocationEnabled,
2930
positionError: null,
@@ -54,6 +55,7 @@ export const geolocated = ({
5455
if (this.isCurrentlyMounted) {
5556
this.setState({
5657
coords: position.coords,
58+
timestamp: position.timestamp,
5759
isGeolocationEnabled: true,
5860
positionError: null,
5961
});
@@ -127,6 +129,7 @@ export const geoPropTypes = {
127129
heading: PropTypes.number,
128130
speed: PropTypes.number,
129131
}),
132+
timestamp: PropTypes.number,
130133
isGeolocationAvailable: PropTypes.bool,
131134
isGeolocationEnabled: PropTypes.bool,
132135
positionError: PropTypes.shape({

tests/typescript/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const StatelessDemo: React.FC<GeolocatedProps> = (props) => (
2424
isGeolocationAvailable: {props.isGeolocationAvailable}
2525
isGeolocationEnabled: {props.isGeolocationEnabled}
2626
positionError: {props.positionError}
27+
coords: {props.coords}
28+
timestamp: {props.timestamp}
2729
</div>
2830
);
2931

0 commit comments

Comments
 (0)