Flutter Web--Location permission does not work on Safari(Mac & iOS)

640

There's a reputable package geolocator by Baseflow, see that it has the Flutter favorite badget.

You can check the web docs and the example they provide, and maybe this fits with your problem.

Good luck 🙂!

Share:
640
Mudassir
Author by

Mudassir

Founder and CEO of MakThis, Inc. Blogs at chapra.blog.

Updated on January 01, 2023

Comments

  • Mudassir
    Mudassir over 1 year

    I am trying to request location in my app. It works in iOS, Android, and every browser except Safari on Mac and iOS.

    EDIT

    Since none of the plugins worked for Safari, I decided to go with native dart2js solution.

    @JS('navigator.geolocation')
    library jslocation;
    
    import 'package:js/js.dart';
    
    @JS('getCurrentPostion')
    external void getCurrentPostion(Function success(GeolocationPostion pos));
    
    @JS()
    @anonymous
    class GeolocationPostion {
      external factory GeolocationPostion({GeolocationCoordinates coords});
    
      external GeolocationCoordinates get coords;
    }
    
    @JS()
    @anonymous
    class GeolocationCoordinates {
      external factory GeolocationCoordinates({
        double latitude,
        double longitude,
      });
    
      external double get latitude;
      external double get longitude;
    }
    
    
    
    double _latitude;
            double _longitude;
    
            getCurrentPostion((pos) => allowInterop((GeolocationPostion pos) {
                  _latitude = pos.coords.latitude;
                  _longitude = pos.coords.longitude;
                }));
    
            return LocationData.fromMap({
              'latitude': _latitude,
              'longitude': _longitude,
            });
    

    The solution is copied wholesale from here. The demo for this post works fine with on Safari. What am I doing wrong?

    • Jabbar
      Jabbar over 2 years
      the only difference I see is that the demo get location when pressing a button! could you try this?
    • Ermiya Eskandary
      Ermiya Eskandary over 2 years
      Do you get any console errors that you can feedback from Safari Mac?
    • Mudassir
      Mudassir over 2 years
      @ErmiyaEskandary No console errors as well.
    • PRATHIV
      PRATHIV about 2 years
      have u found the solution?
    • Mudassir
      Mudassir about 2 years
      @PRATHIV I use reverse geocoding API when its Safari. I am using mapbox, you can use Google Maps.
  • Mudassir
    Mudassir over 2 years
    This was the oeiginal solution tried