谷歌地图不出现 [英] Google map in flutter doesn't appear
问题描述
我正在尝试遵循本教程" https://medium.com/flutter-io/google-maps-and-flutter-cfb330f9a245 ",即可在Flutter中添加Google地图.我用谷歌地图键更新了Android清单,并添加了访问fine_location的权限.我的模拟器上没有显示白色屏幕.我花了很多时间试图修复它,但徒劳无功.我还尝试使用插件" https://pub.dartlang.org/packages/google_maps_flutter#-readme-tab- ",但显示地图没有任何帮助.任何帮助表示赞赏,谢谢
I'm trying to follow this tutorial "https://medium.com/flutter-io/google-maps-and-flutter-cfb330f9a245" to add google map in flutter. I updated android manifest with google map key and added a permission for accessing fine_location.I get white screen on my emulator with no map. i spent many hours trying to fix it but in vain . i also tried the sample usage with plugin "https://pub.dartlang.org/packages/google_maps_flutter#-readme-tab-" but nothing help in showing map . any help is appreciated thanks in advance
推荐答案
实际上,通过上述教程中的问题搜索,我没有找到任何答案.我找到了另一种地图绘制方法,并且可以与我一起正常使用,因此我将其发布,因为它可能会对他人有所帮助.您需要将其添加到pubspec.yaml中以获取插件.2-添加Android和Ios的密钥3-将此代码添加到main中.
Actually I didn't find any answer through my search for issues in above tutorial. I find another way for map and it works fine with my so I'll post it, as it may help others. you need to 1- add it in pubspec.yaml to get plugin . 2- add the key for android and Ios 3- add this code in 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;
}
}
这篇关于谷歌地图不出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!