google_maps_helper 2.0.1 copy "google_maps_helper: ^2.0.1" to clipboard
google_maps_helper: ^2.0.1 copied to clipboard

A flutter package that extends google_maps_flutter with essential functionalities, including autocomplete textfield for places search, polylines drawing, geocoding, and reverse geocoding.

A flutter package that extends google_maps_flutter with essential functionalities, including autocomplete textfield for places search, polylines drawing, geocoding, and reverse geocoding.

Features #

  • All Google map features in one package
  • Auto-complete text field for Google places
  • Draw polylines on Google map
  • [GEOCODING] Get geocode from an address
  • [REVERSE GEOCODING] Get address from geocode
  • No need for separate google_maps_flutter package
  • Easy to use & highly customizable

google_maps_helper screenshot

Getting started #

  • Checkout google_maps_flutter setup instructions.

  • From version 2.0.0 onwards, this package uses the "Places API (New)" for address searches. Please ensure the "Places API (New)" is enabled in your Google Cloud project.

Usage #

Auto-complete text field for Google places #

  Widget get _searchField {
    return GmhSearchField(
      selectedValue: _address,
      onSelected: (data) => _address = data,
      searchParams: GmhSearchParams(apiKey: '<GOOGLE_PLACES_API_NEW_KEY>'),
    );
  }

Use search function to create your own auto complete functionality #

final list = await GmhService().searchAddress(
  text: 'califor',
  params: GmhSearchParams(apiKey: '<GOOGLE_PLACES_API_NEW_KEY>'),
);
print(list.length);
// show this list in your UI

Google map widget #

GoogleMapController? _controller;
final _kSrc = CameraPosition(
    target: LatLng(37.4165849896396, -122.08051867783071),
);
final _kDest = CameraPosition(
    target: LatLng(37.420921119071586, -122.08535335958004),
);

Widget get _map {
  return GmhMap(
    mapOptions: GmhMapOptions(
      mapType: MapType.normal,
      initialCameraPosition: _kSrc,
      onTap: (pos) => _getAddress(pos),
      minMaxZoomPreference: MinMaxZoomPreference(15, 18),
      onMapCreated: (controller) => _controller = controller,
      markers: {
        Marker(markerId: MarkerId('src'), position: _kSrc.target),
        Marker(markerId: MarkerId('dest'), position: _kDest.target),
      },
    ),
    polylineOptions: GmhPolylineOptions(
      geodesic: true,
      color: Colors.blue,
      optimizeWaypoints: true,
      apiKey: '<GOOGLE_DIRECTIONS_API_KEY>',
    ),
  );
}

Geocoding #

Future<void> _getGeocode(String address) async {
  final data = await GmhService().getGeocode(
    address: address,
    apiKey: '<GOOGLE_GEOCODING_API_KEY>',
  );
  print('${data?.lat},${data?.lng}');
}

Reverse Geocoding #

Future<void> _getAddress(LatLng pos) async {
  final data = await GmhService().getAddress(
    lat: pos.latitude,
    lng: pos.longitude,
    apiKey: '<GOOGLE_GEOCODING_API_KEY>',
  );
  print(data?.address);
}

Additional information #

Think you've found a bug, or would like to see a new feature? We'd love to hear about it! Visit the Issues section of the git repository.

7
likes
0
points
59
downloads

Publisher

verified publishervalueoutput.com

Weekly Downloads

A flutter package that extends google_maps_flutter with essential functionalities, including autocomplete textfield for places search, polylines drawing, geocoding, and reverse geocoding.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, google_maps_flutter, http

More

Packages that depend on google_maps_helper