diff --git a/README.md b/README.md index 64f9add1..1f85f545 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ The props passed to the wrapped component are: heading, speed, }, + timestamp, // timestamp of when the last position was retrieved isGeolocationAvailable, // boolean flag indicating that the browser supports the Geolocation API isGeolocationEnabled, // boolean flag indicating that the user has allowed the use of the Geolocation API positionError, // object with the error returned from the Geolocation API call @@ -167,7 +168,7 @@ class Demo extends React.Component { return (
label: {this.props.label} - lattitude: {this.props.coords && this.props.coords.latitude} + latitude: {this.props.coords && this.props.coords.latitude}
); } diff --git a/index.d.ts b/index.d.ts index c70ca206..2369e096 100644 --- a/index.d.ts +++ b/index.d.ts @@ -43,6 +43,10 @@ interface GeolocatedProps { * The Geolocation API's coords object containing latitude, longitude, and accuracy and also optionally containing altitude, altitudeAccuracy, heading and speed. */ coords?: Coordinates; + /** + * The Geolocation API's timestamp value representing the time at which the location was retrieved. + */ + timestamp?: DOMTimeStamp; /** * Flag indicating that the browser supports the Geolocation API. */ diff --git a/src/index.js b/src/index.js index a3a9c0e3..f77309cf 100644 --- a/src/index.js +++ b/src/index.js @@ -24,6 +24,7 @@ export const geolocated = ({ state = { coords: null, + timestamp: null, isGeolocationAvailable: Boolean(geolocationProvider), isGeolocationEnabled: isOptimisticGeolocationEnabled, positionError: null, @@ -54,6 +55,7 @@ export const geolocated = ({ if (this.isCurrentlyMounted) { this.setState({ coords: position.coords, + timestamp: position.timestamp, isGeolocationEnabled: true, positionError: null, }); @@ -127,6 +129,7 @@ export const geoPropTypes = { heading: PropTypes.number, speed: PropTypes.number, }), + timestamp: PropTypes.number, isGeolocationAvailable: PropTypes.bool, isGeolocationEnabled: PropTypes.bool, positionError: PropTypes.shape({ diff --git a/tests/typescript/index.tsx b/tests/typescript/index.tsx index b6945f2d..164bb063 100644 --- a/tests/typescript/index.tsx +++ b/tests/typescript/index.tsx @@ -24,6 +24,8 @@ const StatelessDemo: React.FC = (props) => ( isGeolocationAvailable: {props.isGeolocationAvailable} isGeolocationEnabled: {props.isGeolocationEnabled} positionError: {props.positionError} + coords: {props.coords} + timestamp: {props.timestamp} );