Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geolocate functionality to mapbox-gl-geocoder #444

Merged
merged 11 commits into from
Mar 4, 2022
273 changes: 153 additions & 120 deletions API.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

- Adds `setAccessToken` method to update the accessToken after the Geocoder has been initialized [#449](https://github.com/mapbox/mapbox-gl-geocoder/pull/449)
- Enables use of the value `'ip'` for `proximity` to bias around a user's location [#453](https://github.com/mapbox/mapbox-gl-geocoder/pull/453)
- Adds `events` dependency to resolve a Node emulation issue for use in packagers such as Vite [#451](https://github.com/mapbox/mapbox-gl-geocoder/pull/451)
- Added geolocate functionality [#444](https://github.com/mapbox/mapbox-gl-geocoder/pull/444)

### Dependency update

- Bumps `nanoid` to v3.1.31 to resolve security vulnerability warning.
- Adds `babelify` to build process to ensure mapbox-gl-geocoder remains ES5-compatible.
- Adds `events` dependency to resolve a Node emulation issue for use in packagers such as Vite [#451](https://github.com/mapbox/mapbox-gl-geocoder/pull/451)

## 4.7.4

Expand Down
1 change: 1 addition & 0 deletions debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var coordinatesGeocoder = function(query) {
var geocoder = new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
trackProximity: true,
enableGeolocation: true,
localGeocoder: function(query) {
return coordinatesGeocoder(query);
},
Expand Down
20 changes: 20 additions & 0 deletions lib/geolocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function Geolocation() {}

Geolocation.prototype = {

isSupport: function() {
return Boolean(window.navigator.geolocation);
},

getCurrentPosition: function() {
const positionOptions = {
enableHighAccuracy: true
};

return new Promise(function(resolve, reject) {
window.navigator.geolocation.getCurrentPosition(resolve, reject, positionOptions);
});
},
}

module.exports = Geolocation;
Loading