mohesu / map_location_picker

Map location picker for flutter Based on google_maps_flutter
Apache License 2.0
46 stars 68 forks source link

Result is null when current location button is not clicked #22

Closed bhaskar8088 closed 1 year ago

bhaskar8088 commented 1 year ago

Here is the code I am using:

return MapLocationPicker( apiKey: "key", currentLatLng: location, onNext: (GeocodingResult? result) { if (result != null) { print("result"); print(result); } },

If you see the below image, if I press the round dot icon then if I search for any location in search bar, then its showing the result in onNext. But if I dont press current location icon(round dot icon) and if I search any location in search bar, then its showing the address in the bottom input box but when I click next, onNext is getting result as null.

WhatsApp-Image-2023-08-06-at-14-00-49

I think forcing the user to select current location is not correct. Instead, I want to show the current location automatically. For that, I am using below code:

getLocation() async { LocationPermission permission; permission = await Geolocator.requestPermission(); Position position = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.high); setState(() { lat = position.latitude; lng = position.longitude; location = LatLng(lat, lng); }); setState(() { _currentPosition = location; }); }

This way, I am able to show current location when screen is opened, but when next is clicked, onNext is showing result as null when round dot icon is clicked.

Is there anyway I can auto select current location button or someway so result will not be null when onNext is clicked without user clicking current location button.

Thanks.

rvndsngwn commented 1 year ago

Hi @bhaskar8088 I just added this to the package map_location_picker: ^1.2.5

bhaskar8088 commented 1 year ago

@rvndsngwn Thanks, that worked. But there is another issue.

After I search for any address and after pressing next arrow button, it is showing address(with lat, lng) of current location in the onNext function instead of showing the address of the newly searched location. Can you please fix this too? Thanks.

atg-anil-ahuja commented 1 year ago

@bhaskar8088 i have fixed this issue in my repo you can use this repo https://github.com/atg-anil-ahuja/map_location_picker.git and modify your pubspec.yaml file. map_location_picker: git: url: https://github.com/atg-anil-ahuja/map_location_picker.git ref: master

rvndsngwn commented 1 year ago

Hi @bhaskar8088 the has been resolved