Flutter team has been building Google map plugin for display google map in Ios and Android. In this post, we going to view the progress of Google map plugin. Before starting a google map Flutter project. Let's know about the power of Google map.
.
Google Maps is a web-based service that gives us information about geographical regions around the world. Google Maps offers aerial and satellite views of many places. In some cities, Google Maps offers street views photographs that are taken from its official vehicles.
Google Maps offers several services as part of the larger application, as follows.
1. A route planner offers directions for drivers, bikers, walkers, and users of public transportation who want to take a trip from one location to another.
2. The Google maps application program API's makes it possible for web site administrators to embed Google Maps into a proprietary site such as a real estate guide or community service page.
3. Google maps for mobile offers a location service for motorists that utilizes the Global Positioning System (GPS) location of the mobile device.
4. Google Street View enables users to view and navigate through horizontal and vertical panoramic street-level images of various cities around the world.
As we know, Google Maps SDK have a large API. In this post, we'll cover the following API.
MapView for native Ios and Android application is still in progress. So, we can't add it inside of Flutter hierarchy widgets. But don't worry, we have an alternative solution to use the Google Maps. We can use static map API for show maps inline while using the Google Maps SDK for iOS and Android to allow the user to interact with the full-screen map.
Before start Flutter google map application development we have to get google map API key. So, let's get it first.
Creating your API Key
We have to create a google map key for use Google Map API.
1. First of all, you have to create a google account.
2. After that Sign into https://console.developers.google.com/.
3. On the Google API console, set up a new project.
4. Now move to API dashboard labeled Enable APIs and Services.
5. After that enable the following API for this project
Android — Enable the Google Maps Android API.
Ios — Enable the Google Maps iOS API.
Static Inline Maps — Enable the Google Static Maps API.
6. Next, we have to generate an API key. In the drawer on the left-hand side, tap on Credentials. Then tap the Create Credentials button and select API Key. This will create a new API key that has access to all of the API’s you’ve enabled.
Now, Move to Flutter Application tools. In this project, we use static API to display a static location. You can change it by using the TextField that's a flutter widget. Once, static map load. You can move on the dynamic map after tap on Static Picture. It's all about our project. Let's start its implementation.
1. Create a new Flutter Project and give name flutter_google_map and add google map plugin map_view: "^0.0.12" into pubspec.yaml,
2. After that, we have to do some changes for Ios and Android.
Android
Ios
Set the NSLocationWhenInUseUsageDescription in ios/Runner/Info.plist.
3. Now, move to the core part of Flutter application and edit main. dart file
As you can see above main.dart code snippet initialize the MapView with it's key. We have updated theme of App and created a new dart file map_screen.dart. It'll manage the widget hierarchy of our project.
4. As you can see, we have made map_screen.dart as StateFullWidget. Because we'll render map if found changes on screen.
in this snippet, we have initialized the widgets and created an instance of MapUtil and MapView.
4. Now, we going to create a screen widget that displays static google, three TextField, and a Button. It'll change the static map after edit values.
the above snippet displays a text that'll display before static map visible. When static map load it'll become hide behind the static map.
As you can see, in the above snippet. We created three TextField and Button for change static map.
5. After that create another dart file and give name map_util.dart. Here, We going to write our map methods and we create our static location instance. As you can see, I have given lat and long of my location. You can replace it with your location. In the following until class, you have to replace your google map key.
in the above code snippet, we have created a method for markers and we have given some static location lat and long. When you tab on a static map. In the new window, dynamic google map visible. There you can see markers as well.
At the end, your project structure looks like:
We hope that with this google map plugin you’ll be able to start using maps in your Flutter applications. We will continue to evolve this plugin to try to cover the expansive Google Maps API. If you have any issue to implement the above project. You can get the full source code from Github.
If you have any query regarding the above project feel free to ask it in the comment section below.
.
Google Maps is a web-based service that gives us information about geographical regions around the world. Google Maps offers aerial and satellite views of many places. In some cities, Google Maps offers street views photographs that are taken from its official vehicles.
Google Maps offers several services as part of the larger application, as follows.
1. A route planner offers directions for drivers, bikers, walkers, and users of public transportation who want to take a trip from one location to another.
2. The Google maps application program API's makes it possible for web site administrators to embed Google Maps into a proprietary site such as a real estate guide or community service page.
3. Google maps for mobile offers a location service for motorists that utilizes the Global Positioning System (GPS) location of the mobile device.
4. Google Street View enables users to view and navigate through horizontal and vertical panoramic street-level images of various cities around the world.
As we know, Google Maps SDK have a large API. In this post, we'll cover the following API.
- Markers
- The ability to show maps inline
- Camera Updates
- Map callbacks
MapView for native Ios and Android application is still in progress. So, we can't add it inside of Flutter hierarchy widgets. But don't worry, we have an alternative solution to use the Google Maps. We can use static map API for show maps inline while using the Google Maps SDK for iOS and Android to allow the user to interact with the full-screen map.
Before start Flutter google map application development we have to get google map API key. So, let's get it first.
Creating your API Key
We have to create a google map key for use Google Map API.
1. First of all, you have to create a google account.
2. After that Sign into https://console.developers.google.com/.
3. On the Google API console, set up a new project.
4. Now move to API dashboard labeled Enable APIs and Services.
5. After that enable the following API for this project
Android — Enable the Google Maps Android API.
Ios — Enable the Google Maps iOS API.
Static Inline Maps — Enable the Google Static Maps API.
6. Next, we have to generate an API key. In the drawer on the left-hand side, tap on Credentials. Then tap the Create Credentials button and select API Key. This will create a new API key that has access to all of the API’s you’ve enabled.
Now, Move to Flutter Application tools. In this project, we use static API to display a static location. You can change it by using the TextField that's a flutter widget. Once, static map load. You can move on the dynamic map after tap on Static Picture. It's all about our project. Let's start its implementation.
1. Create a new Flutter Project and give name flutter_google_map and add google map plugin map_view: "^0.0.12" into pubspec.yaml,
2. After that, we have to do some changes for Ios and Android.
Android
- In your AndroidManifest.xml, add the following uses-permission above the <application> tag.
- In your AndroidManifest.xml, add the following lines inside of the application tag. Be sure to replace your google map API.
- Add the MapActivity to your AndroidManifest.xml
- After that move to android/build.gradle file. Under buildScript dependencies and add it.
Ios
Set the NSLocationWhenInUseUsageDescription in ios/Runner/Info.plist.
3. Now, move to the core part of Flutter application and edit main. dart file
4. As you can see, we have made map_screen.dart as StateFullWidget. Because we'll render map if found changes on screen.
4. Now, we going to create a screen widget that displays static google, three TextField, and a Button. It'll change the static map after edit values.
Now, let's merge the above code and you will see complete map_screen.dart look like below:
5. After that create another dart file and give name map_util.dart. Here, We going to write our map methods and we create our static location instance. As you can see, I have given lat and long of my location. You can replace it with your location. In the following until class, you have to replace your google map key.
At the end, your project structure looks like:
We hope that with this google map plugin you’ll be able to start using maps in your Flutter applications. We will continue to evolve this plugin to try to cover the expansive Google Maps API. If you have any issue to implement the above project. You can get the full source code from Github.
Flutter - How can draw route on google map between markers.
Flutter - Google map widget pluginIf you have any query regarding the above project feel free to ask it in the comment section below.