Singorenko
Singorenko

Reputation: 513

GoogleMaps plugin for flutter shows only the markers on ios simulator

I am using the Google Maps plugin for flutter: https://pub.dartlang.org/packages/google_maps_flutter

For Android, the application shows the map and the makers on Physical device and the emulator, but on the simulator of iPhone, I see only the markers on a grey screen as in the image.

enter image description here

I was trying with different keys from the API, no one seems to work.

this is the code for iOS(I could not find the AppDelegate.m so I added into 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)
  }
}

in Info.plist:

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

and the Flutter widget code:

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,
      )),
    );
  }
}

Anyone could help me or explain why this is not working on the iOS simulator?

Upvotes: 2

Views: 2177

Answers (4)

Divya Thakkar
Divya Thakkar

Reputation: 212

Please check your API key first for Google map service. Is it enable for iOS or not

So, enabling Maps SDK for iOS platform should work.

Also, check your installed XCode and target sdk version: it must be higher than iOS version 12.0

Upvotes: 0

AhabLives
AhabLives

Reputation: 1468

Two possible issues when I ran into this issue.

  1. Make sure you have enabled "Maps SDK for iOS" in your api console "https://console.cloud.google.com/google/maps-apis/......."

  2. Make sure your bundle ID name matches your console settings bundle ID name.

Upvotes: 3

Randal Schwartz
Randal Schwartz

Reputation: 44176

Keep in mind this plugin is a developer preview at version 0.2. Many things are probably not working yet.

Upvotes: 0

Loan
Loan

Reputation: 142

Did you activate the location on the simulator?

Upvotes: 0

Related Questions