question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The map does not appear (or is empty)

See original GitHub issue

Describe the bug The map is not shown in browser, simulator or native device. I see an error in the console of the simulator: Unhandled Promise Rejection: DataCloneError: The object can not be cloned. from the function postToNative in the main function nativeBridge.

To Reproduce Steps to reproduce the behavior:

  1. Install a fresh version of Ionic with Capacitor
  2. Install the plugin @capacitor-community/google-maps
  3. Configure the plugin as indicated in the official doc
  4. Launch the function ionic cap run ios --open and then, open the simulator.
  5. In the simulator the map does not appears.
  6. Open the console to see the error.

Expected behavior The map should appears without error in the console.

Thanks for your help, Loïc

Screenshots

HTML

<ion-content [fullscreen]="true">
  <div id="map" #map></div>
</ion-content>

SCSS

#map {
  width: 100%;
  height: 100%;
}

TypeScript Code

import { Component, ElementRef, ViewChild } from '@angular/core';
import { CapacitorGoogleMaps } from "@capacitor-community/google-maps";

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {

@ViewChild('map') mapView: ElementRef;

constructor() {
  CapacitorGoogleMaps.initialize({
    key: "MY-API-KEY",
    devicePixelRatio: window.devicePixelRatio
  });
}

ionViewDidEnter() {
  this.createMap();
}

async createMap() {
  const element = this.mapView.nativeElement;
  const boundingRect = element.getBoundingClientRect() as DOMRect;
  
  let result = await CapacitorGoogleMaps.createMap({
      element: element,
      boundingRect: boundingRect,
      cameraPosition: {
        target: {
          latitude: 33.6,
          longitude: -117.9
        }
      }
    });
    
    element.style.background = "";
    element.setAttribute("map", result.googleMap.mapId);
  }

}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tafelnlcommented, May 29, 2022
  1. You can read more about adding the map to a modal in these issues: #154 and #161
  2. Yes you can have multiple map instances

But please use the search function / discussions / Stack Overflow for these kind of questions so we can keep everything organized 😃

Closing this issue since it’s solved now

1reaction
loicparentcommented, May 25, 2022

Hello,

Many thanks for your help @va2ron1!

Ok so after comparing and testing, there are 2 things that was wrong.

First, I didn’t use the css variable to set transparency to the ion-content. So use the css variable instead of the property is ok:

ion-content {
  --background: transparent;
}

Second, the console error related to the cloned element is due to the fact that I had the key element in the “CreateMapOptions” object. So when I remove the key, this is ok:

let result = await CapacitorGoogleMaps.createMap({
  boundingRect: {
   width: Math.round(boundingRect.width),
   height: Math.round(boundingRect.height),
   x: Math.round(boundingRect.x),
   y: Math.round(boundingRect.y),
 },
 cameraPosition: {
   target: {
     latitude: 33.6,
     longitude: -117.9
  }
 }
});

So now, this is ok and I have updated the repository here.

I have an additional question: Is it possible to show the map in a modal and having multiple map instances?

Thanks again 😃 Loïc

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to check if a Map or Set is empty? - javascript
Show activity on this post. For both cases you can use const populatedSet = new Set(['foo']); console.log(populatedSet.size); // should be 1.
Read more >
Map does not display in Layout - ArcGIS Pro 3 - Esri Community
Map frame is blank in layout. The data is visible in the map view but when I add the map frame to the...
Read more >
Apple Photos "Places" map is empty, despi…
After upgrading to Catalina, Apple Photos "Places", which views photos by geotag on a map, is empty (shows no photos, just an empty...
Read more >
Empty places with no information show up in google maps
I see one place in google maps which has the green i-want-to-go-there-marker, but when i click it, it comes up empty, it doesn't...
Read more >
Map visualization does not show and blank
Map visualization does not work, only showing white blank (second picture below). I have clear cache. I have enalabled map (in admin portal, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found