Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Radar.initialize('prj_test_pk_...', { /* options */ });

Add the following script in your `html` file
```html
<script src="https://js.radar.com/v4.5.7/radar.min.js"></script>
<script src="https://js.radar.com/v4.5.8-beta.0/radar.min.js"></script>
```

Then initialize the Radar SDK
Expand All @@ -73,8 +73,8 @@ To create a map, first initialize the Radar SDK with your publishable key. Then
```html
<html>
<head>
<link href="https://js.radar.com/v4.5.7/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.5.7/radar.min.js"></script>
<link href="https://js.radar.com/v4.5.8-beta.0/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.5.8-beta.0/radar.min.js"></script>
</head>

<body>
Expand All @@ -98,8 +98,8 @@ To create an autocomplete input, first initialize the Radar SDK with your publis
```html
<html>
<head>
<link href="https://js.radar.com/v4.5.7/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.5.7/radar.min.js"></script>
<link href="https://js.radar.com/v4.5.8-beta.0/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.5.8-beta.0/radar.min.js"></script>
</head>

<body>
Expand Down Expand Up @@ -130,8 +130,8 @@ To power [geofencing](https://radar.com/documentation/geofencing/overview) exper
```html
<html>
<head>
<link href="https://js.radar.com/v4.5.7/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.5.7/radar.min.js"></script>
<link href="https://js.radar.com/v4.5.8-beta.0/radar.css" rel="stylesheet">
<script src="https://js.radar.com/v4.5.8-beta.0/radar.min.js"></script>
</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "radar-sdk-js",
"version": "4.5.7",
"version": "4.5.8-beta.0",
"description": "Web Javascript SDK for Radar, location infrastructure for mobile and web apps.",
"homepage": "https://radar.com",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/api/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TrackAPI {
// if latitude & longitude are not provided,
// try and retrieve device location (will prompt for location permissions)
if (!latitude || !longitude) {
const deviceLocation = await Navigator.getCurrentPosition({ desiredAccuracy });
const deviceLocation = await Navigator.getCurrentPosition({ desiredAccuracy }, fraud);
latitude = deviceLocation.latitude;
longitude = deviceLocation.longitude;
accuracy = deviceLocation.accuracy;
Expand Down
28 changes: 25 additions & 3 deletions src/navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ import { RadarLocationError, RadarPermissionsError } from './errors';

import type { LocationAuthorization, NavigatorPosition } from './types';

const radarGeolocation = (() => {
if (!navigator) {
return null;
}

const g = navigator.geolocation;

if (!g) {
return null;
}

const emptyFn = () => {};

return Object.freeze({
getCurrentPosition: g.getCurrentPosition ? g.getCurrentPosition.bind(g) : emptyFn,
watchPosition: g.watchPosition ? g.watchPosition.bind(g) : emptyFn,
clearWatch: g.clearWatch ? g.clearWatch.bind(g) : emptyFn,
});
})();

interface PositionOptionOverrides {
desiredAccuracy?: string;
}
Expand All @@ -21,11 +41,13 @@ const useHighAccuracy = (desiredAccuracy?: string) => (
);

class Navigator {
public static async getCurrentPosition(overrides: PositionOptionOverrides = {}): Promise<NavigatorPosition> {
public static async getCurrentPosition(overrides: PositionOptionOverrides = {}, fraud: Boolean = false): Promise<NavigatorPosition> {
return new Promise((resolve, reject) => {
const options = Config.get();

if (!navigator || !navigator.geolocation) {
const g = fraud ? radarGeolocation : navigator.geolocation;

if (!g) {
return reject(new RadarLocationError('navigator.geolocation is not available.'));
}

Expand Down Expand Up @@ -67,7 +89,7 @@ class Navigator {
Logger.info(`Using geolocation options: ${JSON.stringify(positionOptions)}`);

// get current location from browser
navigator.geolocation.getCurrentPosition(
g.getCurrentPosition(
(position) => {
if (!position || !position.coords) {
return reject(new RadarLocationError('device location return empty coordinates.'));
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '4.5.7';
export default '4.5.8-beta.0';
Loading