Home > Blockchain >  Cannot integrade google-maps into flutter, plugin not loading
Cannot integrade google-maps into flutter, plugin not loading

Time:01-12

I am trying to follow the "Adding Google Maps to a Flutter app" tutorial from link: enter image description here

What am I doing wrong?

Any help would be really appreciated.

CodePudding user response:

Try this basic Map code, hope you understand and if you have any doubts please feel free to ask in the comments section.

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Maps',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MapView(),
    );
  }
}

class MapView extends StatefulWidget {
  @override
  _MapViewState createState() => _MapViewState();
}

class _MapViewState extends State<MapView> {
  CameraPosition _initialLocation = CameraPosition(target: LatLng(37.42796133580664, -122.085749655962),zoom: 14.4746);
  GoogleMapController mapController;

  @override
  Widget build(BuildContext context) {
    var height = MediaQuery.of(context).size.height;
    var width = MediaQuery.of(context).size.width;

    return Container(
      height: height,
      width: width,
      child: Scaffold(
        body: Stack(
          children: <Widget>[
            GoogleMap(
              initialCameraPosition: _initialLocation,
              myLocationEnabled: true,
              myLocationButtonEnabled: false,
              mapType: MapType.normal,
              zoomGesturesEnabled: true,
              zoomControlsEnabled: false,
              onMapCreated: (GoogleMapController controller) {
              mapController = controller;
                 },
             ),
          ],
        ),
      ),
    );
  }

CodePudding user response:

The last comment above that the web version is not supported was the problem. Tried with the mobile emulator and everything worked right. Thanks

  •  Tags:  
  • Related