getting current location in flutter code example

Example 1: flutter geolocator web

@JS('navigator.geolocation') // navigator.geolocation namespace
 library jslocation; // library name can be whatever you want

 import "package:js/js.dart";

@JS('getCurrentPosition') // Accessing method getCurrentPosition 
from       Geolocation API
external void getCurrentPosition(Function success(GeolocationPosition pos));

@JS()
@anonymous
class GeolocationCoordinates {
  external double get latitude;
  external double get longitude;
  external double get altitude;
  external double get accuracy;
  external double get altitudeAccuracy;
  external double get heading;
  external double get speed;

external factory GeolocationCoordinates(
  {double latitude,
  double longitude,
  double altitude,
  double accuracy,
  double altitudeAccuracy,
  double heading,
  double speed});
  }

@JS()
@anonymous
class GeolocationPosition {
external GeolocationCoordinates get coords;

external factory GeolocationPosition({GeolocationCoordinates 
coords});
}

______________________________

NEW FILE

______________________________

 import 'package:Shared/locationJs.dart';

  success(pos) {
     try {
       print(pos.coords.latitude);
       print(pos.coords.longitude);
       } catch (ex) {
        print("Exception thrown : " + ex.toString());
         }
     }

  _getCurrentLocation() {
      if (kIsWeb) {
        getCurrentPosition(allowInterop((pos) => success(pos)));
                }
      }

Example 2: currunt location in flutter

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

void main() => runApp(MapScreen());

class MapScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Map",
      home: MapActivity(),
    );
  }
}

class MapActivity extends StatefulWidget {
  @override
  _MapActivityState createState() => _MapActivityState();
}

class _MapActivityState extends State<MapActivity> {
  LatLng _center ;
  Position currentLocation;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getUserLocation();
  }

 Future<Position> locateUser() async {
    return Geolocator()
        .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
  }

  getUserLocation() async {
    currentLocation = await locateUser();
    setState(() {
      _center = LatLng(currentLocation.latitude, currentLocation.longitude);
    });
    print('center $_center');
  }
}

Example 3: get my location in flutter

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Example 4: get location name in flutter

import 'package:geocoder/geocoder.dart';

// From a query
final query = "1600 Amphiteatre Parkway, Mountain View";
var addresses = await Geocoder.local.findAddressesFromQuery(query);
var first = addresses.first;
print("${first.featureName} : ${first.coordinates}");

// From coordinates
final coordinates = new Coordinates(1.10, 45.50);
addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
first = addresses.first;
print("${first.featureName} : ${first.addressLine}");