location_plus

Plugin to get current location, ip address, geocoding, reverse geocoding, and you can also calculate the distance between two coordinates easily

Getting Started

Add into your pubspec.yaml
===========================
location_plus:
Get current location
======================================================

String? _locality = "unknown";
String? _postalCode = "unknown";
String? _administrativeArea = "unknown";
String? _country = "unknown";
double? _latitude = 0;
double? _longitude = 0;
String? _ipAddress = "0";

Future<dynamic> getCurrentLocation() async {
var result = await LocationPlus.getCurrentLocation();
setState(() {
    print(result);
    _locality = result['locality'];
    _postalCode = result['postalCode'];
    _administrativeArea = result['administrativeArea'];
    _country = result['country'];
    _latitude = double.parse(result['latitude']);
    _longitude = double.parse(result['longitude']);
    _ipAddress = result['ipAddress'];
});
}


Text("Locality: $_locality"),
Text("PostalCode: $_postalCode"),
Text("AdministrativeArea: $_administrativeArea"),
Text("Country: $_country"),
Text("Latitude: $_latitude"),
Text("Longitude: $_longitude"),
Text("IPAddress: $_ipAddress"),
ElevatedButton(
    onPressed: () {
    getCurrentLocation();
    },
    child: Text("Click me to get your location")),
SizedBox(
height: 16,
)


Calculate distance between two coordinates
=======================================================

String? _distance = "0";

Future<void> calculateDistanceBetweenTwoCoordinates(double startLatitude,
      double startLongitude, double endLatitude, double endLongitude) async {
    _distance = await _channel.invokeMethod(
        'calculateDistanceBetweenTwoCoordinates', <String, double>{
      'startLatitude': startLatitude,
      'startLongitude': startLongitude,
      'endLatitude': endLatitude,
      'endLongitude': endLongitude,
    });
    setState(() {
      print("distancee: ${_distance}");
    });
  }


Text("Distance: $_distance"),
ElevatedButton(
    onPressed: () {
    calculateDistanceBetweenTwoCoordinates(
        28.7965736573, 77.7635654, 28.8736573, 77.76546124);
    },
    child: Text("Click me to get distance")
)

IOS Setup

Add into Info.plist
==================================================
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Description</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Will you allow this app to always know your location?</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Do you allow this app to know your current location?</string>

Android Setup

Add into Manifest
=================================================== 
<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"/>