gpt4 book ai didi

ios - 用于 flutter 的 GoogleMaps 插件仅显示 ios 模拟器上的标记

转载 作者:IT王子 更新时间:2023-10-29 06:58:41 26 4
gpt4 key购买 nike

我正在为 flutter 使用 Google map 插件:https://pub.dartlang.org/packages/google_maps_flutter

对于 Android,该应用程序在物理设备和模拟器上显示 map 和标记,但在 iPhone 的模拟器上,我只能在灰色屏幕上看到图像中的标记。

enter image description here

我尝试使用来自 API 的不同 key ,但似乎没有一个有效。

这是 iOS 的代码(我找不到 AppDelegate.m 所以我添加到 AppDelegate.switf):

import UIKit
import Flutter
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
GMSServices.provideAPIKey("MY_KEY") // Add this line!
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

在 Info.plist 中:

<key>io.flutter.embedded_views_preview</key>
<string>YES</string>

和 Flutter 小部件代码:

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:father_home_flutter/model/constants.dart';
import 'package:father_home_flutter/model/grown_group_list.dart';
import 'package:father_home_flutter/model/grown_group.dart';
import 'package:father_home_flutter/model/list_church_data.dart';
import 'package:father_home_flutter/model/church_data.dart';

class MapScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() => new _MapScreenState();
}

class _MapScreenState extends State<MapScreen> {
final List<GrownGroup> listGroups = GrownGroupList.getGrownList();
final List<ChurchData> listChurch = ListChurchData.getListChurch();

GoogleMapController mapController;
final LatLng _center = const LatLng(55.751244, 37.618423);

void _onMapCreated(GoogleMapController controller) {
mapController = controller;

//shows group list on a red marker
for (int i = 0; i < listGroups.length; i++) {
mapController.addMarker(MarkerOptions(
position: listGroups[i].latLng,
infoWindowText: InfoWindowText(
listGroups[i].name + " " + listGroups[i].hour,
listGroups[i].phoneNumber)));
}

//shows church on a blue marker

for (int i = 0; i < listChurch.length; i++) {
mapController.addMarker(MarkerOptions(
icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueBlue),
position: listChurch[i].latLng,
infoWindowText:
InfoWindowText(listChurch[i].name, listChurch[i].schedule)));
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Найти нас',
style: Constants.myTextStyleAppBar,
),
elevation: Constants.myElevationAppBar,
backgroundColor: Constants.myAppBarColor,
iconTheme: Constants.myIconThemeDataAppBar,
),
body: SafeArea(
child: GoogleMap(
onMapCreated: _onMapCreated,
)),
);
}
}

任何人都可以帮助我或解释为什么这在 iOS 模拟器上不起作用?

最佳答案

当我遇到这个问题时有两个可能的问题。

  1. 确保您已在 API 控制台“https://console.cloud.google.com/google/maps-apis/ ......”中启用“iOS 版 Maps SDK”

  2. 确保您的包 ID 名称与您的控制台设置包 ID 名称匹配。

关于ios - 用于 flutter 的 GoogleMaps 插件仅显示 ios 模拟器上的标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54442371/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com