浏览器中的Google地图不会显示

问题描述 投票:-2回答:1

我正在尝试按照本教程“https://medium.com/flutter-io/google-maps-and-flutter-cfb330f9a245”来添加谷歌地图。我用谷歌地图密钥更新了android清单,并添加了访问fine_location的权限。我的模拟器上没有地图的白屏。我花了很多时间试图解决它,但徒劳无功。我也尝试使用插件“https://pub.dartlang.org/packages/google_maps_flutter#-readme-tab-”的示例用法,但没有任何帮助显示地图。任何帮助表示感谢提前

google-maps dart flutter
1个回答
0
投票

实际上我没有找到任何答案通过我在上面的教程中搜索问题。我找到了另一种地图方式,它与我的工作正常,所以我会发布它,因为它可能会帮助其他人。你需要1-在pubspec.yaml中添加它来获取插件。 2-添加Android和Ios的密钥3-在main中添加此代码。

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

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  GoogleMapController myMapController;
  final Set<Marker> _markers = new Set();
  static const LatLng _mainLocation = const LatLng(25.69893, 32.6421);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(
              title: Text('Maps With Marker'),
              backgroundColor: Colors.blue[900],
            ),
            body: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Expanded(
                  child: GoogleMap(
                    initialCameraPosition: CameraPosition(
                      target: _mainLocation,
                      zoom: 10.0,
                    ),
                    markers: this.myMarker(),
                    mapType: MapType.normal,
                    onMapCreated: (controller) {
                      setState(() {
                        myMapController = controller;
                      });
                    },
                  ),
                ),
              ],
            )));
  }

  Set<Marker> myMarker() {
    setState(() {
      _markers.add(Marker(
        // This marker id can be anything that uniquely identifies each marker.
        markerId: MarkerId(_mainLocation.toString()),
        position: _mainLocation,
        infoWindow: InfoWindow(
          title: 'Historical City',
          snippet: '5 Star Rating',
        ),
        icon: BitmapDescriptor.defaultMarker,
      ));
    });

    return _markers;
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.