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

问题描述 投票:1回答:3

我正在使用Google Maps插件进行扑动:https://pub.dartlang.org/packages/google_maps_flutter

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

enter image description here

我尝试使用API​​中的不同键,似乎没有人工作。

这是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模拟器?

ios google-maps flutter
3个回答
1
投票

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

  1. 确保在api控制台“https://console.cloud.google.com/google/maps-apis/ .......”中启用了“Maps SDK for iOS”
  2. 确保您的软件包ID名称与控制台设置软件包ID名称匹配。

0
投票

你在模拟器上激活了位置吗?


0
投票

请记住,此插件是版本0.2的开发人员预览版。许多事情可能还没有奏效。

© www.soinside.com 2019 - 2024. All rights reserved.