Home > Enterprise >  Flutter marker appears but not map
Flutter marker appears but not map

Time:01-13

I am using flutter and trying to implement a google map.

As you can see from the picture, the marker renders in the right position, it just has no actual map rendered. Additionally, I am trying to have the address search bar autocomplete, and nothing is resulting as well. You can check out the code for this in the second block below.

Expanded(
  child: GoogleMap(
    onMapCreated: _onMapCreated, initialCameraPosition:
      CameraPosition(
        target: _center,
        zoom: 11.0,
      ),
     markers: {
       Marker(markerId: MarkerId(searchField.text),
              position: _center)
     },
    ),
  )

I already created an API key, and put it into my app. I followed the tutorials for incorporating it in, but am still left with nothing.

For iOS, I registered it in my AppDelegate.swift and in the geomethods for the address searching mechanism. I also prompted for location permissions in the Info.plist. Is there anything I am missing?

// geoMethods
final geoMethods = GeoMethods(
    googleApiKey: '(My API key was here, deleted for obvious reasons)',
    language: 'en',
    countryCode: 'us',
    countryCodes: ['us', 'es', 'co'],
    country: 'United States',
    city: 'New York',
  );

...
...
...

// Passed in for the search bar text field
onTap: () => showDialog(
  context: context,
  builder: (_) => AddressSearchBuilder.deft(
    geoMethods: geoMethods,
    controller: field,
    builder: AddressDialogBuilder(
      color: Color(0xFFE64225),
    ),
    onDone: (Address address) {
      print(address);
    },
  ),
)

enter image description here

CodePudding user response:

once check your API key. some time map not load because of expired API key. if googleApiKey is working fine then check your AppDelegate.swift file

import UIKit
import Flutter
import GoogleMaps


@UIApplicationMain
 @objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
  ) -> Bool {
    GMSServices.provideAPIKey("your_ googleApiKey_here")
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
  •  Tags:  
  • Related