Flutter Programming

Hands On No. 6 : Working with Maps

Resources
Code of main.dart

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State createState() => _MyAppState();
}

class _MyAppState extends State {
  late GoogleMapController mapController;


  final LatLng _center = const LatLng(22.29301284148933, 73.12225873737414);

  void _onMapCreated(GoogleMapController controller) {
    mapController = controller;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        useMaterial3: true,
        colorSchemeSeed: Colors.green[500],
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Navrachana University'),
          elevation: 2,
        ),
        body: GoogleMap(
          onMapCreated: _onMapCreated,
          initialCameraPosition: CameraPosition(
            target: _center,
            zoom: 8.0,
          ),
        ),
      ),
    );
  }
}

								   

Code of AndroidManifest.xml

<meta-data android:name="com.google.android.geo.API_KEY"
android:value="Replace with your API Key"/>