meloDramatic007 / search_map_location

MIT License
7 stars 11 forks source link

search_map_location

search_map_location is a text search widget used to search geo location by name.It has severel call back and customization option to handle the place search.

Getting Started

To install, add it to your pubspec.yaml file:

dependencies:
    search_map_location: 0.0.6

After that, make sure you have the following APIs activated in your Google Cloud Platform:

You can now import it to your file and use it on your app.

import 'package:search_map_location/search_map_location.dart';
Widget build(BuildContext context) {
  return Scaffold(
    body: Center(
      child: SearchLocation(
        apiKey: // YOUR GOOGLE MAPS API KEY
        onSelected: (Place place){
        print(place.description);

         },
      )
    )
  );
}

The constructor has 8 attributes related to the API:

The Place class

This class will be returned on the onSelected and onSearch methods. It allows us to get more information about the user selected place.

Initially, it provides you with only basic information:

However, you can get more information like the coordinates and the bounds of the place by calling

await place.geolocation;

Example

Here's an example of the widget using country :

return SearchLocation(
    apiKey: YOUR_API_KEY,
    // The language of the autocompletion
    language: 'en',
    //Search only work for this specific country
    country: 'BD',
    onSelected: (Place place) async {
        final geolocation = await place.geolocation;

        // Will animate the GoogleMap camera, taking us to the selected position with an appropriate zoom
        final GoogleMapController controller = await _mapController.future;
        controller.animateCamera(CameraUpdate.newLatLng(geolocation.coordinates));
        controller.animateCamera(CameraUpdate.newLatLngBounds(geolocation.bounds, 0));
    },
);

Here's an example of the widget using location and radius :

return SearchLocation(
    apiKey: YOUR_API_KEY,
    // The language of the autocompletion
    language: 'en',
    // location is the center of a place and the radius provided here are between this radius of this place search result
    //will be provided,you can set this LatLng dynamically by getting user lat and long in double value
    location: LatLng(latitude: 9.072264, longitude: 7.491302),
    radius: 1100,
    onSelected: (Place place) async {
        final geolocation = await place.geolocation;

        // Will animate the GoogleMap camera, taking us to the selected position with an appropriate zoom
        final GoogleMapController controller = await _mapController.future;
        controller.animateCamera(CameraUpdate.newLatLng(geolocation.coordinates));
        controller.animateCamera(CameraUpdate.newLatLngBounds(geolocation.bounds, 0));
    },
);