liodali / osm_flutter

OpenStreetMap plugin for flutter
https://pub.dev/packages/flutter_osm_plugin
MIT License
239 stars 98 forks source link

myLocation does not return in reasonable time #482

Closed vargab95 closed 10 months ago

vargab95 commented 11 months ago

I implemented the following simple app to play around with osm_flutter. However, my attempt has failed. My idea was to open the map, get the user's location, go to that location and zoom in. I tested it with an android emulator and on a real phone as well and in both cases, I see only the "calling mylocation" message and it does not print the position even after minutes. Maybe I'm doing something wrong. The version is 0.70.3.

import 'package:flutter/material.dart';
import 'package:flutter_osm_plugin/flutter_osm_plugin.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyMapPage(),
    );
  }
}

class MyMapPage extends StatefulWidget {
  const MyMapPage({super.key});

  @override
  State<MyMapPage> createState() => _MyMapPageState();
}

class _MyMapPageState extends State<MyMapPage> {
  late MapController _controller;

  @override
  void initState() {
    super.initState();
    _controller = MapController.withUserPosition();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: OSMFlutter(
        controller: _controller,
        osmOption: const OSMOption(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          print('calling mylocation');
          _controller.myLocation().then((position) {
            print(position.toString());
          });
        },
        child: const Icon(Icons.location_searching),
      ),
    );
  }
}
STRENCH0 commented 11 months ago

Same problem. Also I found that onMapIsReadyhas never been invoked with true. So it may be linked with that problem

sajjad-n commented 11 months ago

+1

YoavSl commented 11 months ago

+1

KseniaKeren commented 11 months ago

+1

davidnir1 commented 11 months ago

+1, really need this.. thanks!

TomerIluz commented 11 months ago

+2!

liodali commented 11 months ago

we published new version contain fix thnx for @vargab95 for the fix the new version 0.70.4 in future versions we will support external userLocationHandler where you can manage it from your app directly or use any plugin/package for that

liodali commented 10 months ago

check our latest version : 1.0.0-dev.1

vargab95 commented 10 months ago

Thanks for the fix! It works fine with 1.0.0-dev.3. The above example prints "calling mylocation" closely followed by the location data as it was expected.