simple_location_picker 0.0.4 copy "simple_location_picker: ^0.0.4" to clipboard
simple_location_picker: ^0.0.4 copied to clipboard

A Simple Location Picker for Flutter using OpenStreetMap. Pick any location from openstreetmaps or use it to display a fixed location.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:simple_location_picker/simple_location_picker_screen.dart';
import 'package:simple_location_picker/simple_location_result.dart';
import 'package:simple_location_picker/utils/slp_constants.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Simple Location Picker Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Simple Location Picker Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({required this.title});

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  SimpleLocationResult? _selectedLocation;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Center(
        child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
            SizedBox(height: 50),

        // The button that opens the SimpleLocationPicker in display ONLY mode.
        // This opens the SimpleLocationPicker to display a specific location on the map with a marker.
        ElevatedButton(
          child: Text("Display a location"),
          onPressed: () {
            double latitude = _selectedLocation?.latitude ??
                SLPConstants.DEFAULT_LATITUDE;
            double longitude = _selectedLocation?.longitude ??
                SLPConstants.DEFAULT_LONGITUDE;
            Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (context) =>
                        SimpleLocationPicker(
                          initialLatitude: latitude,
                          initialLongitude: longitude,
                          appBarTitle: "Display Location",
                          displayOnly: true,
                        )));
          },
        ),
        SizedBox(height: 50),

        // The button that opens the SimpleLocationPicker in picker mode.
        // This opens the SimpleLocationPicker to allow the user to pick a location from the map.
        // The SimpleLocationPicker returns SimpleLocationResult containing the lat, lng of the picked location.
        ElevatedButton(
          child: Text("Pick a Location"),
          onPressed: () {
            double latitude = _selectedLocation?.latitude ??
                SLPConstants.DEFAULT_LATITUDE;
            double longitude = _selectedLocation?.longitude ??
                SLPConstants.DEFAULT_LONGITUDE;
            Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (context) =>
                        SimpleLocationPicker(
                          initialLatitude: latitude,
                          initialLongitude: longitude,
                          appBarTitle: "Select Location",
                        ))).then((value) {
              if (value != null) {
                setState(() {
                  _selectedLocation = value;
                });
              }
            });
          },
        ),

        SizedBox(height: 50),
        // Displays the picked location on the screen as text.
        _selectedLocation != null ? Text(
            'SELECTED: (${_selectedLocation?.latitude}, ${_selectedLocation
                ?.longitude})') : Container(),
        ],
      ),
    ));
  }
}
8
likes
140
points
42
downloads

Publisher

unverified uploader

Weekly Downloads

A Simple Location Picker for Flutter using OpenStreetMap. Pick any location from openstreetmaps or use it to display a fixed location.

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_map, flutter_map_cancellable_tile_provider, flutter_web_plugins, latlong2

More

Packages that depend on simple_location_picker