Skip to content

Commit

Permalink
fix(location): location bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
azarz committed Nov 29, 2023
1 parent 8d92fca commit f6fd407
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
<!-- Permissions -->

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>
17 changes: 16 additions & 1 deletion android/app/src/main/java/fr/ign/geoportail/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
package fr.ign.geoportail;

import android.os.Bundle;
import android.webkit.WebView;

import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {}
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
public void onStart() {
super.onStart();
WebView webview = getBridge().getWebView();
webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"build": "webpack --config webpack.config.js",
"build:dev": "webpack --config dev.config.js",
"serve:dev": "webpack-dev-server --config dev.config.js",
"run:android": "npm run build:dev && npx cap sync && npx cap run android"
"run:android": "npm run build:dev && npx cap sync && npx cap run android",
"build:android": "npm run build && npx cap sync && cd android && ./gradlew assembleRelease",
"build:android:dev": "npm run build:dev && npx cap sync && cd android && ./gradlew"
},
"keywords": [
"ecosystem:capacitor"
Expand Down
48 changes: 25 additions & 23 deletions src/js/services/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,29 @@ const moveTo = (coords, zoom=Globals.map.getZoom(), panTo=true, gps=true) => {
* Suit la position de l'utilisateur
*/
const trackLocation = () => {
let lastAccuracy = 100000;
Geolocation.checkPermissions().then((status) => {
if (status.location != 'denied') {
Geolocation.getCurrentPosition({
maximumAge: 0,
timeout: 10000,
enableHighAccuracy: true
}).then((position) => {
moveTo({
lat: position.coords.latitude,
lon: position.coords.longitude
}, Math.max(Globals.map.getZoom(), 14));
}).catch((err) => {
console.warn(`${err.message}`);
});

var firstLocation = true;
Geolocation.watchPosition({
maximumAge: 0,
timeout: 10000,
enableHighAccuracy: true
},
(position) => {
moveTo({
lat: position.coords.latitude,
lon: position.coords.longitude
}, Globals.map.getZoom(), tracking_active);
if (location_active && position && position.coords.accuracy <= Math.max(lastAccuracy, 16) ) {
lastAccuracy = position.coords.accuracy;
currentPosition = position;
var zoom = Globals.map.getZoom();
if (firstLocation) {
zoom = Math.max(Globals.map.getZoom(), 14);
firstLocation = false;
}
moveTo({
lat: position.coords.latitude,
lon: position.coords.longitude
}, zoom, tracking_active);
}
}).then( (watchId) => {
watch_id = watchId
}).catch((err) => {
Expand Down Expand Up @@ -168,6 +166,7 @@ const locationOnOff = async () => {
DOM.$geolocateBtn.style.backgroundImage = 'url("' + LocationImg + '")';
Geolocation.clearWatch({id: watch_id});
clean();
currentPosition = null;
location_active = false;
tracking_active = false;
Toast.show({
Expand Down Expand Up @@ -203,12 +202,15 @@ const getOrientation = (event) => {
*/
const getLocation = async (tracking) => {
var results = null;
enablePosition(tracking);
var position = await Geolocation.getCurrentPosition({
maximumAge: 0,
timeout: 10000,
enableHighAccuracy: true
})
var position = currentPosition;
if (currentPosition === null) {
enablePosition(tracking);
var position = await Geolocation.getCurrentPosition({
maximumAge: 0,
timeout: 10000,
enableHighAccuracy: true
});
}

results = {
coordinates : {
Expand Down

0 comments on commit f6fd407

Please sign in to comment.