flutter maps
a flutter app using google maps sdk & directions api
plugins
the plugins used in this project are:
features
- detect the current location of the user
- use geocoding for converting addresses to coordinates and vice versa
- add markers to the map view
- draw the route between two places using polylines and directions api
- calculate the actual distance of the route
usage
before using it, you will need to make a new project in the google cloud platform, and enable the google maps api for that project. also, don’t forget to setup the billing for that project on gcp, otherwise you will receive the following error:
-
download the repository.
sbis04/flutter_maps.git
-
open the project using your favorite ide. for opening with vs code:
code flutter_maps
-
for the android part, go to
android/app/src/main/androidmanifest.xml
file and add your api key here.<!-- add your google maps api key here --> <meta-data android:name="com.google.android.geo.api_key" android:value="your key here"/>
-
for the ios part, go to
ios/runner/appdelegate.swift
file and add your api key here.gmsservices.provideapikey("your key here")
-
go to the
lib/secrets.dart
file and add your api key here.
full configuration (already done in this project)
you do not require to complete these configurations if you are cloning this project, as they are already done in it. but these may be helpful if you are setting up a new flutter project for using google maps and location services.
android setup
-
navigate to the file
android/app/src/main/androidmanifest.xml
and add the following code snippet inside theapplication
tag:<!-- add your google maps api key here --> <meta-data android:name="com.google.android.geo.api_key" android:value="your key here"/>
-
also, you will need location access in the app. so, add the following permission in the same file inside the
manifest
tag:<uses-permission android:name="android.permission.access_fine_location"/>
ios setup
-
navigate to the file
ios/runner/appdelegate.swift
and replace the whole code with the following:import uikit import flutter import googlemaps @uiapplicationmain @objc class appdelegate: flutterappdelegate { override func application( _ application: uiapplication, didfinishlaunchingwithoptions launchoptions: [uiapplication.launchoptionskey: any]? ) -> bool { //add your google maps api key here gmsservices.provideapikey("your key here") generatedpluginregistrant.register(with: self) return super.application(application, didfinishlaunchingwithoptions: launchoptions) } }
-
also, add the following to
ios/runner/info.plist
file:<key>io.flutter.embedded_views_preview</key> <string>yes</string>
-
for getting location permission, add the following to the same file:
<key>nslocationwheninuseusagedescription</key> <string>this app needs access to location when open.</string>
this completes the setup for both the platforms in flutter.
license
copyright (c) 2020 souvik biswas
permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “software”), to deal
in the software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the software, and to permit persons to whom the software is
furnished to do so, subject to the following conditions:
the above copyright notice and this permission notice shall be included in all
copies or substantial portions of the software.
the software is provided “as is”, without warranty of any kind, express or
implied, including but not limited to the warranties of merchantability,
fitness for a particular purpose and noninfringement. in no event shall the
authors or copyright holders be liable for any claim, damages or other
liability, whether in an action of contract, tort or otherwise, arising from,
out of or in connection with the software or the use or other dealings in the
software.
Comments are closed.