Fetch Current Location in Flutter

Save

Nowadays, working with Maps and location is very common. In today’s blog will learn how to fetch current location in Flutter.

Using the Flutter Location plugin is very each to fetch the current location of the user on Android and iOS devices.

Read about the variety of Flutter App Development Services offered by Mobikul.

In this blog, we will show the map and display the current location using a marker.

Please follow below Steps to fetch current location in Flutter:

Step1: Add dependencies.

To fetch the current location we use location plugin

But in our project we have also displayed the map so we are using google_maps_flutter to display the map.

Add below code in pubspec.yaml file

Step2: Providing permissions in iOS and Android app to fetch location.

In Android all dependencies and permissions are automatically added to your project with flutter 1.12.

But if you are using Flutter before 1.12 please follow this.

For iOS please add below permissions in your info.plist file.

Step3: Implement Code

We have created a MapScreen class to show our Map and fetch the location.

Please check below function to  fetch the location.

Please check the complete MapScreen file code below.

Now, check below main.dart file code.

Finally, you can run the code, and see the below results.

For more interesting blogs check out here – https://mobikul.com/blog/

Hope this blog helped you for a better understanding of Location and Maps in flutter.

Thanks for reading 🙂

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


2 comments

  • Rohini
    Pakka……. Working fine……
    • Shikha Melkani (Moderator)
      Yes
  • css.php

    Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.

    Hussein Zawia

    Hussein Zawia

    Co-founder, 24Dokan

    Talk to Sales

    Global

    Live Chat
    Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home