1

I am implementing google_maps_picker in my flutter application and I am facing a weird issue where the FloatCard result is only shown after I press the getMyLocation button, otherwise it just shows the CircularProgressIndicator.

 import 'package:flutter/material.dart';
    // import 'package:google_maps/google_maps.dart';
    import 'package:google_maps/google_maps.dart';
    import 'package:google_maps_place_picker/google_maps_place_picker.dart'
        as place;
    // import 'package:location/location.dart';
    
    import '../components/location_helper.dart';
    // import '../components/location_helper.dart';
    
    class MapScreen extends StatelessWidget {
      final LatLng location1 = LatLng(37.657, -122.776);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(
              title: Text('Map Screen'),
            ),
            body: Center(
              child: place.PlacePicker(
                  apiKey: GOOGLE_API,
                  useCurrentLocation: true,
                  onPlacePicked: (result) {
                    print(result.addressComponents);
                    Navigator.of(context).pop();
                  }),
            ));
      }
    }

enter image description here

Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
mustafa zaki
  • 367
  • 1
  • 6
  • 20

2 Answers2

0

for ios phone you need to use selectedPlaceWidgetBuilder instead of onPlacePicked and add this code before return :

selectedPlaceWidgetBuilder: (_, selectedPlace, state, isSearchBarFocused) {

   if (Platform.isIOS) {
      if (selectedPlace != null) {
         state = SearchingState.Idle;
      }
   }

   return...
}
0

This should work just fine. We included selectedPlaceWidgetBuilder for iOS to update searched locations on screen, make usePlaceDetailSearch: true also.

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:google_maps_place_picker/google_maps_place_picker.dart';

class MapUi extends StatelessWidget {
  final LatLng location1 = LatLng(37.657, -122.776);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
          child: PlacePicker(
              apiKey: GoogleMap.APIKEY,
              initialPosition: location1,
              useCurrentLocation: true,
              selectInitialPosition: true,
              usePlaceDetailSearch: true,
              searchForInitialValue: true,
              onPlacePicked: (result) {
                print(result.addressComponents);
                Navigator.of(context).pop();
              },
              selectedPlaceWidgetBuilder:
                  (_, selectedPlace, state, isSearchBarFocused) {
                if (Platform.isIOS) {
                  if (selectedPlace != null) {
                    state = SearchingState.Idle;
                  }
                }

                return Padding(
                  padding: const EdgeInsets.only(top: 80.0, left: 15),
                  child: Text(selectedPlace!.formattedAddress.toString(),
                      style: TextStyle(fontSize: 25)),
                );
              }),
        ));
  }
}
Daniyal
  • 11
  • 2
yobo zorle
  • 348
  • 3
  • 8