skip to Main Content

No implementation found for method placemarkFromCoordinates on channel
flutter.baseflow.com/geocoding

Here is my Location Provider code:

  List<Placemark> placemarks =
      await placemarkFromCoordinates(latitude, longitude);
  selectedAddress = placemarks.first;

I have tried changing the method but i dont understand the root of the erro. Is placemarkfromCoordinates depreceated. What is the appropriate way to fix this?

2

Answers


  1. Chosen as BEST ANSWER

    The geocoding library in Flutter provides several methods other than placemarkFromCoordinates for converting a location's coordinates into a human-readable address or location information:

    1. placemarkFromAddress - This method takes a string representing an address and returns a list of Placemark objects that match the address.

    2. placemarkFromQuery - This method takes a string representing a query and returns a list of Placemark objects that match the query. The query can be any text that describes a location, such as a landmark, an address, or a city name.

    3. locationFromAddress - This method takes a string representing an address and returns a Location object containing the latitude and longitude of the address.

    4. locationFromQuery - This method takes a string representing a query and returns a Location object containing the latitude and longitude of the location that matches the query.

    5. placesNearby - This method takes a Location object and a radius in meters and returns a list of Place objects that are within the specified radius of the location.

    6. placesAutocomplete - This method takes a string representing a query and returns a list of AutocompletePrediction objects that match the query. The predictions can be used to provide autocomplete suggestions for a location search.

    Here are code examples to help:

    // Get placemark from address
    final addresses = await placemarkFromAddress('1600 Amphitheatre Parkway, Mountain View, CA');
    final selectedAddress = addresses.first;
    print(selectedAddress);
    
    // Get location from query
    final location = await locationFromQuery('Central Park, New York, NY');
    print(location.latitude);
    print(location.longitude);
    
    // Get places nearby
    final places = await placesNearby(Location(40.748817, -73.985428), 1000);
    places.forEach((place) {
      print(place.name);
    });
    
    // Get autocomplete predictions
    final predictions = await placesAutocomplete('Times Square');
    predictions.forEach((prediction) {
      print(prediction.description);
    });
    

  2. Same question! Here’s a bunch of links and code I’ve tried researching, nothing works. The above answer doesn’t help because it requires the user to type into a text box their location information (placemarkFromAddress, locationFromQuery etc) but in most cases the current location should be automatic!

        import 'package:flutter/material.dart';
        import 'package:geocoding/geocoding.dart' hide Location;
        import 'package:geolocator/geolocator.dart';
        import 'package:provider/provider.dart';
        //import 'package:geocode/geocode.dart';
        import 'package:location/location.dart';
        import 'package:flutter/services.dart';
        
        //==============
        //   Attempt
        //==============
        Future<void> _getCurrentLocation() async {
            Position position = await Geolocator.getCurrentPosition();
            //final GeoCode geoCode = GeoCode();
            //final longitude = position.longitude;
            //final latitude = position.latitude;
            // Get the address from the current location
            try {
              //final addresses = await geoCode.reverseGeocoding(longitude, latitude);
              //final first = addresses.first;
        
              List<Placemark> placemarks =
                  await placemarkFromCoordinates(position.longitude, position.latitude);
        
              setState(() {
                _currentLocation = '${placemarks[0].subAdministrativeArea.toString()},'
                    '${placemarks[0].administrativeArea.toString()},'
                    '${placemarks[0].country.toString()}';
                _isLoading = false;
              });
            } catch (e) {
              // ignore: avoid_print
              print(e);
              // ignore: avoid_print
              print('CURRENT LOCATION DIDN’T WORK');
              _isLoading = false;
            }
    
    
        //==============
        //   Attempt
        //==============  
         Future<void> _getCurrentLocation() async {
          Position position = await Geolocator.getCurrentPosition();
          GeoCode geoCode = GeoCode();
        
          // Get the address from the current location
          try {
            // Reverse geocode the latitude and longitude to get the address
            List<Address> addresses = await geoCode.reverseGeocoding(
                latitude: position.latitude, longitude: position.longitude) as List<Address>;
            Address address = addresses.first;
        
            setState(() {
              _currentLocation =
                  '${address.street}, ${address.locality}, ${address.countryName}';
              _isLoading = false;
            });
          } catch (e) {
            print(e.toString());
            _isLoading = false;
          }
        }
    
    //==============
    //   Attempt
    //==============
    Future<void> _getAddressFromLatLng() async {
        try {
          List<Placemark> placemarks = await placemarkFromCoordinates(
              _currentLocation2.latitude, _currentLocation2.longitude);
    
          Placemark place = placemarks[0];
    
          setState(() {
            _currentAddress = "${place.locality}, ${place.country}";
          });
        } catch (e) {
          print(e);
        }
      }
    
      //==============
      //   Attempt
      //==============
      Future<Position> _getCurrentLocation2() async {
        bool serviceEnabled;
        LocationPermission permission;
        serviceEnabled = await Geolocator.isLocationServiceEnabled();
        if (!serviceEnabled) {
          return Future.error('Location services are disabled.');
        }
        permission = await Geolocator.checkPermission();
        if (permission == LocationPermission.denied) {
          permission = await Geolocator.requestPermission();
          if (permission == LocationPermission.denied) {
            return Future.error('Location permissions are denied');
          }
        }
        if (permission == LocationPermission.deniedForever) {
          // Permissions are denied forever, handle appropriately.
          return Future.error(
              'Location permissions are permanently denied, we cannot request permissions.');
        }
        await Geolocator.getCurrentPosition(forceAndroidLocationManager: true)
            .then((position) {
          setState(() {
            _currentLocation2 = position;
            _getAddressFromLatLng();
          });
        }).catchError((e) {
          print(e);
        });
        return await Geolocator.getCurrentPosition();
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search