ionic-team / ionic-native-google-maps

Google maps plugin for Ionic Native
Other
221 stars 125 forks source link

Cannot scroll, tilt, rotate and zoom the map after setting visibility of Markers or Circles on the map. #284

Closed tomfong closed 4 years ago

tomfong commented 4 years ago

I'm submitting a ... (check one with "x")

If you choose 'problem or bug report', please select OS: (check one with "x")

cordova information: (run $> cordova plugin list)

cordova-plugin-autostart 2.3.0 "Autostart"
cordova-plugin-background-mode 0.7.3 "BackgroundMode"
cordova-plugin-ble-central 1.2.4 "BLE"
cordova-plugin-browsertab 0.2.0 "cordova-plugin-browsertab"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-geolocation 4.0.2 "Geolocation"
cordova-plugin-googlemaps 2.6.2 "cordova-plugin-googlemaps"
cordova-plugin-inappbrowser 3.2.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 4.1.3 "cordova-plugin-ionic-webview"
cordova-plugin-nativestorage 2.3.2 "NativeStorage"
cordova-plugin-splashscreen 5.0.3 "Splashscreen"
cordova-plugin-statusbar 2.4.3 "StatusBar"
cordova-plugin-whitelist 1.3.4 "Whitelist"
cordova.plugins.diagnostic 5.0.1 "Diagnostic"

If you use @ionic-native/google-maps, please tell the package.json (only @ionic-native/core and @ionic-native/google-maps are fine mostly)

{
  "name": "myApp",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~8.1.2",
    "@angular/compiler": "~8.1.2",
    "@angular/core": "~8.1.2",
    "@angular/forms": "~8.1.2",
    "@angular/platform-browser": "~8.1.2",
    "@angular/platform-browser-dynamic": "~8.1.2",
    "@angular/router": "~8.1.2",
    "@ionic-native/autostart": "^5.19.1",
    "@ionic-native/background-mode": "^5.19.1",
    "@ionic-native/ble": "^5.19.0",
    "@ionic-native/browser-tab": "^5.19.1",
    "@ionic-native/core": "^5.19.1",
    "@ionic-native/diagnostic": "^5.19.0",
    "@ionic-native/geolocation": "^5.19.0",
    "@ionic-native/google-maps": "^5.5.0",
    "@ionic-native/in-app-browser": "^5.19.1",
    "@ionic-native/native-storage": "^5.18.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic/angular": "^4.11.7",
    "@ionic/core": "^4.11.7",
    "@ionic/storage": "^2.2.0",
    "cordova-android": "^8.1.0",
    "cordova-browser": "^6.0.0",
    "cordova-ios": "^5.1.1",
    "cordova-plugin-autostart": "^2.3.0",
    "cordova-plugin-background-mode": "^0.7.3",
    "cordova-plugin-ble-central": "^1.2.4",
    "cordova-plugin-browsertab": "^0.2.0",
    "cordova-plugin-compat": "^1.2.0",
    "cordova-plugin-geolocation": "^4.0.2",
    "cordova-plugin-googlemaps": "^2.6.2",
    "cordova-plugin-inappbrowser": "^3.2.0",
    "cordova-plugin-nativestorage": "^2.3.2",
    "cordova.plugins.diagnostic": "^5.0.1",
    "core-js": "^2.5.4",
    "ionic-angular": "^3.9.9",
    "rxjs": "~6.5.1",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.801.2",
    "@angular-devkit/build-angular": "^0.803.21",
    "@angular-devkit/core": "~8.1.2",
    "@angular-devkit/schematics": "~8.1.2",
    "@angular/cli": "~8.1.2",
    "@angular/compiler": "~8.1.2",
    "@angular/compiler-cli": "~8.1.2",
    "@angular/language-service": "~8.1.2",
    "@compodoc/compodoc": "^1.1.11",
    "@ionic/angular-toolkit": "~2.0.0",
    "@ionic/lab": "2.0.13",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-ionic-webview": "^4.1.3",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.4.3"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-nativestorage": {},
      "cordova-plugin-ble-central": {
      },
      "cordova-plugin-geolocation": {},
      "cordova.plugins.diagnostic": {
        "ANDROID_SUPPORT_VERSION": "28.+"
      },
      "cordova-plugin-background-mode": {},
      "cordova-plugin-autostart": {},
      "cordova-plugin-googlemaps": {
        "API_KEY_FOR_ANDROID": "(My API)",
        "API_KEY_FOR_IOS": "(My API)",
        "PLAY_SERVICES_VERSION": "15.0.1",
        "ANDROID_SUPPORT_V4_VERSION": "27.+",
        "LOCATION_WHEN_IN_USE_DESCRIPTION": "This app wants to get your location while this app runs only.",
        "LOCATION_ALWAYS_USAGE_DESCRIPTION": "This app wants to get your location always, even this app runs in background."
      },
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-browsertab": {}
    },
    "platforms": [
      "browser",
      "android"
    ]
  }
}

Current behavior: When I click a button to set some Marker and Circle visible, they become visible but the gesture of the map is not functional. I can only drag the map upwards but cannot drag to other directions unless I leave the page and enter the page again.

Expected behavior: After setting visibility of some Marker and Circle, the gesture of the map should function normally.

wf9a5m75 commented 4 years ago

Please share your project files on GitHub. Without your code, I can't help

tomfong commented 4 years ago

Please share your project files on GitHub. Without your code, I can't help

page.html

<div id="map_canvas"></div>
<ion-content>
<ng-container *ngFor="let person of people">
  <ion-item (click)="showMarker(person)">
      Show Marker
  </ion-item>
</ng-container>
</ion-content>

page.scss

#map_canvas {
  height: 40%;
}

page.ts

import { Component, OnInit } from '@angular/core';
import { Platform } from '@ionic/angular';
import { GoogleMap, GoogleMaps, Environment, Marker, GoogleMapsAnimation, GoogleMapsEvent } from '@ionic-native/google-maps/ngx';

export class Page implements OnInit {

  map: GoogleMap;
  markers = {};
  circles = {};
  people = [{...}]; // contains person objects

  constructor(
    private platform: Platform,
  ) {
      this.initializeMarkers();
  }

  loadMap() {
    Environment.setEnv({
      'API_KEY_FOR_BROWSER_RELEASE': (My API),
      'API_KEY_FOR_BROWSER_DEBUG': (My API),
    });
    this.map = GoogleMaps.create('map_canvas', {
      camera: {
        target: {
          lat: 114,
          lng: 22,
        },
        zoom: 9,
        tilt: 0,
      },
      controls: {
        myLocationButton: true,
        myLocation: true,
        compass: true,
      },
      gestures: {
        scroll: true,
        tilt: true,
        rotate: true,
        zoom: true,
      },
    });
    this.map.clear();
  }

  async initializeMarkers() {
    this.map.clear();
    this.markers = {};
    this.circles = {};
    for (const person of this.people) {
        await this.map.addMarker({
          title: person.alias,
          position: { lat: 114, lng: 22 },
          visible: false,
          animation: GoogleMapsAnimation.DROP,
        }).then(
          marker => {
            this.markers[person.uuid] = marker;
          }
        );
        await this.map.addCircle({
          radius: 30,
          center: this.markers[person.uuid].getPosition(),
          fillColor: 'rgba(0, 0, 255, 0.5)',
          strokeColor: 'rgba(0, 0, 255, 0.75)',
          strokeWidth: 1,
          visible: false,
        }).then(
          circle => {
            this.circles[person.uuid] = circle;
          }
        );
        this.markers[person.uuid].bindTo('position', this.circles[person.uuid], 'center');
    }
  }

  showMarker(person: any) {
    const marker = this.markers[person.uuid];
    const circle = this.circles[person.uuid];
    if (marker.isVisible()) {
      marker.hideInfoWindow();
      marker.setVisible(false);
      circle.setVisible(false);
    } else {
      marker.showInfoWindow();
      marker.setVisible(true);
      circle.setVisible(true);
    }
    this.map.setAllGesturesEnabled(true);
  }

  ngOnInit() {
    this.platform.ready().then(() => this.loadMap());
  }

}

Suppose "people" is a valid array that contains "person" objects with key UUID.

wf9a5m75 commented 4 years ago
<ion-content>
<div id="map_canvas"></div>
<ng-container *ngFor="let person of people">
  <ion-item (click)="showMarker(person)">
      Show Marker
  </ion-item>
</ng-container>
</ion-content>
tomfong commented 4 years ago
<ion-content>
<div id="map_canvas"></div>
<ng-container *ngFor="let person of people">
  <ion-item (click)="showMarker(person)">
      Show Marker
  </ion-item>
</ng-container>
</ion-content>

No, it's not an issue... div element must be outside ion-content, otherwise the map cannot be visible. And the map is functional and draggable unless I make markers visible/invisible.

wf9a5m75 commented 4 years ago

Please share your project "files(not past code)" on GitHub.

tomfong commented 4 years ago
<ion-content>
<div id="map_canvas"></div>
<ng-container *ngFor="let person of people">
  <ion-item (click)="showMarker(person)">
      Show Marker
  </ion-item>
</ng-container>
</ion-content>

sorry... yours is solution, and I will close this issue.