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

[Bug]: altitude property still 0 #1414

Closed
3 of 8 tasks
andreastambazzi opened this issue Jan 26, 2024 · 4 comments
Closed
3 of 8 tasks

[Bug]: altitude property still 0 #1414

andreastambazzi opened this issue Jan 26, 2024 · 4 comments
Labels
P1 High-priority issues at the top of the work list. platform: android Issue is related to the Android platform. type: bug Something isn't working

Comments

@andreastambazzi
Copy link

Please check the following before submitting a new issue.

Please select affected platform(s)

  • Android
  • iOS
  • Linux
  • macOS
  • Web
  • Windows

Steps to reproduce

I'm using geolocator version

geolocator: ^10.1.0

on Android 11

i'm trying to stream out the position with

positionStream = Geolocator
.getPositionStream(locationSettings: locationSettings)
.listen( (Position? position) {

  if ( position == null ) {
    logger.info("getPositionStream: null");     
  }
  else {
    logger.info("getPositionStream: ${position.latitude.toString()}, ${position.longitude.toString()} ${position.altitude.toString} ");
  }
  
  if ( onPositionChange != null ) {
    onPositionChange(position);
  }

});

with configuration as follow

locationSettings = AndroidSettings(
accuracy: LocationAccuracy.high,
distanceFilter = 5,
intervalDuration = Duration(seconds: 5),
forceLocationManager: true,
intervalDuration: intervalDuration,
useMSLAltitude: true,
);

Expected results

I was expecting a valorized altitude with longitude and latitude.

Actual results

Altitude still ever setted up at 0.

What is worng?

Code sample

Code sample
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutterTestApp/Utils/Logger.dart';
import 'package:geolocator/geolocator.dart';


///#############################################################################
/// 
///
class AppGeolocator {

  Logger                            logger = Logger("AppGeolocator");
  late LocationSettings             locationSettings;
  late StreamSubscription<Position> positionStream;
  late LocationAccuracy             locationAccurancy;
  late int                          distanceFilter;     
  late Duration                     intervalDuration;
  

  ///---------------------------------------------------------------------------
  ///
  ///
  AppGeolocator( { void Function(Position?)? onPositionChange } ){

    logger.info("AppGeolocator init");

    locationAccurancy = LocationAccuracy.high;
    distanceFilter    = 5;
    intervalDuration  = Duration(seconds: 5);

    if (defaultTargetPlatform == TargetPlatform.android) {      

      locationSettings = AndroidSettings(
        accuracy: locationAccurancy,
        distanceFilter: distanceFilter,
        forceLocationManager: true,
        intervalDuration: intervalDuration,
        useMSLAltitude: true
        /// I've tryed with parameter also setted up as false ... but with same result
        ///  useMSLAltitude: false 
 
      );

    } 
    else if (defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.macOS) {
      locationSettings = AppleSettings(
        accuracy: locationAccurancy,        
        activityType: ActivityType.fitness,
        distanceFilter: distanceFilter,
        pauseLocationUpdatesAutomatically: true,
        showBackgroundLocationIndicator: false,        
      );

    } 
    else {
        locationSettings = LocationSettings(
        accuracy: locationAccurancy,
        distanceFilter: distanceFilter,
      );
    }

    ///
    /// Position Streaming 
    ///
    positionStream = Geolocator
      .getPositionStream(locationSettings: locationSettings)
      .listen( (Position? position) {

        if ( position == null ) {
          logger.info("getPositionStream: null");     
        }
        else {
          logger.info("getPositionStream: ${position.latitude.toString()}, ${position.longitude.toString()} ${position.altitude.toString()}");
        }
        
        if ( onPositionChange != null ) {
          onPositionChange(position);
        }

      });
        
  }


  ///---------------------------------------------------------------------------
  /// Get current position
  ///
  Future<Position?> getCurrentPosition() async {

    bool               serviceEnabled;
    LocationPermission permission;

    serviceEnabled = await Geolocator.isLocationServiceEnabled();

    if (!serviceEnabled) {
      logger.error("getCurrentPosition Location services are disabled");
      return null;
    }

    permission = await Geolocator.checkPermission();

    if (permission == LocationPermission.denied) {

      permission = await Geolocator.requestPermission();

      if (permission == LocationPermission.denied) {
        logger.error("getCurrentPosition Location permissions are denied'");
        return null;
      }
    }
    
    if (permission == LocationPermission.deniedForever) {
      logger.error("getCurrentPosition Location permissions are permanently denied, we cannot request permissions.");
      return null;      
    } 

    return await Geolocator.getCurrentPosition(
      desiredAccuracy: locationAccurancy,
      timeLimit: Duration(seconds: 2)
    );

  }


}

Screenshots or video

Screenshots or video demonstration

Version

10.1.0

Flutter Doctor output

Doctor output
s ~/work/Projects/flutter/flutter_test_app $ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.9, on macOS 13.6.4 22G513 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[!] Xcode - develop for iOS and macOS (Xcode 15.2)
    ✗ CocoaPods installed but not working.
        You appear to have CocoaPods installed but it is not working.
        This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
        This can usually be fixed by re-installing CocoaPods.
      To re-install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Community Edition (version 2023.2.5)
[✓] VS Code (version 1.85.2)
[✓] Connected device (3 available)            
[✓] Network resources

! Doctor found issues in 1 category.
@Wackymax
Copy link
Contributor

Wackymax commented Jan 28, 2024

Fixed in #1415

Use this to get the fix while we wait for the PR process:

dependency_overrides:
  geolocator_android:
    git:
      url: https://github.com/Wackymax/flutter-geolocator.git
      path: geolocator_android
      ref: 135277e44e8283bae5473691324405fe360c844e

@mvanbeusekom mvanbeusekom added type: bug Something isn't working platform: android Issue is related to the Android platform. P1 High-priority issues at the top of the work list. labels Jan 29, 2024
@TimHoogstrate
Copy link
Contributor

Fixed in #1415

Use this to get the fix while we wait for the PR process:

dependency_overrides:
  geolocator_android:
    git:
      url: https://github.com/Wackymax/flutter-geolocator.git
      path: geolocator_android
      ref: 135277e44e8283bae5473691324405fe360c844e

The pr is merged, I'll close this issue. Feel free to reopen when needed op open a new issue.

@andreastambazzi
Copy link
Author

andreastambazzi commented Jan 29, 2024

thank you, i'm waiting for the flutter module update at the upper version ...

@Wackymax
Copy link
Contributor

Wackymax commented Jan 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 High-priority issues at the top of the work list. platform: android Issue is related to the Android platform. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants