First of create your google developer api console account and configure your app with enable map library.
Create project : if you don’t have an existing project then create new one click on ‘create project’
if you have a project then search and select your project
click on ‘create project’ then show this screen after that put project name and click on create
after creating your project then show this screen and selectable credentials option
we will click on ‘create credentials’ after show dialog and click on ‘API key’
after that show a dialog and create your api key but not configure your app so click on ‘restrict key’
after click show this screen. In package name filed put your package name which define in your project manifest file and also put your SHA-1 key in sha-1 key filed.
after put all information then click on ‘save’ button
your project configure but not enable android map library so click on library option in menu bar
after click on library then show this screen and click on ‘maps sdk for android’
click ‘enable’ button than your project configure with map sdk
after that configure your project on google developer api console. we will goes to project main file
Add dependency : add dependency in your app gradle file
dependencies { implementation 'com.google.android.gms:play-services-maps:17.0.0' }
Add api key in your manifest file
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAPD2Zrr3aCGnPcTkYQqViAtF3jFtWn6us"/> //replace your api key
also add following permission in manifest file
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Main.java file
import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.databinding.DataBindingUtil; import android.Manifest; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.pm.PackageManager; import android.os.Bundle; import android.widget.Toast; import com.example.mymap.databinding.ActivityMainBinding; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class MainActivity extends AppCompatActivity implements OnMapReadyCallback { ActivityMainBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(this, R.layout.activity_main); binding.mapView.onCreate(savedInstanceState); // checkLocationPermission(); binding.mapView.getMapAsync(this); } @Override public void onMapReady(GoogleMap googleMap) { // Creating a marker MarkerOptions markerOptions = new MarkerOptions(); // Setting the position for the marker markerOptions.position(new LatLng(26.9124, 75.7873)); // Animating to the marker position googleMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(26.9124, 75.7873))); // Placing a marker on the touched position googleMap.addMarker(markerOptions); } @Override public void onResume() { binding.mapView.onResume(); super.onResume(); } @Override public void onPause() { super.onPause(); binding.mapView.onPause(); } @Override public void onDestroy() { super.onDestroy(); binding.mapView.onDestroy(); } @Override public void onLowMemory() { super.onLowMemory(); binding.mapView.onLowMemory(); } }
Main.xml file
<?xml version="1.0" encoding="utf-8"?> <layout> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <com.google.android.gms.maps.MapView android:id="@+id/mapView" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> </layout>
First of create your google developer api console account and configure your app with enable map library.
Create project : if you don’t have an existing project then create new one click on ‘create project’
if you have a project then search and select your project
click on ‘create project’ then show this screen after that put project name and click on create
after creating your project then show this screen and selectable credentials option
we will click on ‘create credentials’ after show dialog and click on ‘API key’
after that show a dialog and create your api key but not configure your app so click on ‘restrict key’
after click show this screen. In package name filed put your package name which define in your project manifest file and also put your SHA-1 key in sha-1 key filed.
after put all information then click on ‘save’ button
your project configure but not enable android map library so click on library option in menu bar
after click on library then show this screen and click on ‘maps sdk for android’
click ‘enable’ button than your project configure with map sdk
after that configure your project on google developer api console. we will goes to project main file
Add dependency : add dependency in your app gradle file
dependencies { implementation 'com.google.android.gms:play-services-maps:17.0.0' }
Add api key in your manifest file
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAPD2Zrr3aCGnPcTkYQqViAtF3jFtWn6us"/> //replace your api key
also add following permission in manifest file
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Main.java file
import android.Manifest import android.app.AlertDialog import android.content.pm.PackageManager import android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.databinding.DataBindingUtil import com.example.mymap.MainActivity import com.example.mymap.databinding.ActivityMainBinding import com.google.android.gms.maps.CameraUpdateFactory import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.OnMapReadyCallback import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.MarkerOptions class MainActivity : AppCompatActivity(), OnMapReadyCallback { var binding: ActivityMainBinding? = null var mGoogleMap: GoogleMap? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = DataBindingUtil.setContentView(this, R.layout.activity_main) binding?.mapView?.onCreate(savedInstanceState) // checkLocationPermission(); binding?.mapView?.getMapAsync(this) } override fun onMapReady(googleMap: GoogleMap) { // mGoogleMap = googleMap; // Creating a marker val markerOptions = MarkerOptions() // Setting the position for the marker markerOptions.position(LatLng(26.9124, 75.7873)) // Animating to the marker position googleMap.animateCamera(CameraUpdateFactory.newLatLng(LatLng(26.9124, 75.7873))) // Placing a marker on the touched position googleMap.addMarker(markerOptions) } public override fun onResume() { binding!!.mapView.onResume() super.onResume() } public override fun onPause() { super.onPause() binding!!.mapView.onPause() } public override fun onDestroy() { super.onDestroy() binding!!.mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() binding!!.mapView.onLowMemory() } }
Main.xml file
<?xml version="1.0" encoding="utf-8"?> <layout> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <com.google.android.gms.maps.MapView android:id="@+id/mapView" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> </layout>
First of create your google developer api console account and configure your app with enable map library for android. if you want to set for IOS then click here
Create project : if you don’t have an existing project then create new one click on ‘create project’
if you have a project then search and select your project
click on ‘create project’ then show this screen after that put project name and click on create
after creating your project then show this screen and selectable credentials option
we will click on ‘create credentials’ after show dialog and click on ‘API key’
after that show a dialog and create your api key but not configure your app so click on ‘restrict key’
after click show this screen. In package name filed put your package name which define in your project manifest file and also put your SHA-1 key in sha-1 key filed.
after put all information then click on ‘save’ button
your project configure but not enable android map library so click on library option in menu bar
after click on library then show this screen and click on ‘maps sdk for android’
click ‘enable’ button than your project configure with map sdk
Add dependency : add dependency in ‘pubspec.yaml’ file
dependencies: google_maps_flutter: ^1.0.3
Add api key in android manifest file
<meta-data android:name="com.google.android.geo.API_KEY" android:value="Your-api-key"/>
Map dart file
import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( // This is the theme of your application. // // Try running your application with "flutter run". You'll see the // application has a blue toolbar. Then, without quitting the app, try // changing the primarySwatch below to Colors.green and then invoke // "hot reload" (press "r" in the console where you ran "flutter run", // or simply save your changes to "hot reload" in a Flutter IDE). // Notice that the counter didn't reset back to zero; the application // is not restarted. primarySwatch: Colors.blue, // This makes the visual density adapt to the platform that you run // the app on. For desktop platforms, the controls will be smaller and // closer together (more dense) than on mobile platforms. visualDensity: VisualDensity.adaptivePlatformDensity, ), home: MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); // This widget is the home page of your application. It is stateful, meaning // that it has a State object (defined below) that contains fields that affect // how it looks. // This class is the configuration for the state. It holds the values (in this // case the title) provided by the parent (in this case the App widget) and // used by the build method of the State. Fields in a Widget subclass are // always marked "final". final String title; @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { GoogleMapController mapController; final LatLng _center = const LatLng(26.9124, 75.7873); void _onMapCreated(GoogleMapController controller) { mapController = controller; } @override Widget build(BuildContext context) { // This method is rerun every time setState is called, for instance as done // by the _incrementCounter method above. // // The Flutter framework has been optimized to make rerunning build methods // fast, so that you can just rebuild anything that needs updating rather // than having to individually change instances of widgets. return Scaffold( appBar: AppBar( title: Text('Maps Sample App'), backgroundColor: Colors.green[700], ), body: GoogleMap( onMapCreated: _onMapCreated, initialCameraPosition: CameraPosition( target: _center, zoom: 15.0, ), ), ); } }