最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to remove map controls on angular + ionic + capacitor - Stack Overflow

programmeradmin4浏览0评论

I have an angular + ionic + capacitor project where I want to show a map with a searchbar and a card, I am using google maps but I want to remove the UI controls, like the yellow guy for the streetview, the + and - for the zoom etc.

export class HomePage implements AfterViewInit {
  @ViewChild('map') mapRef!: ElementRef;
  newMap!: GoogleMap;

  async ngAfterViewInit() {
    await this.getCurrentLocation();
  }

  async getCurrentLocation() {
    try {
      const coordinates = await Geolocation.getCurrentPosition();
      const lat = coordinates.coords.latitude;
      const lng = coordinates.coords.longitude;

      await this.createMap(lat, lng);
    } catch (error) {
      console.error('Error in function getCurrentLocation', error);
    }
  }

  async createMap(lat: number, lng: number) {
    this.newMap = await GoogleMap.create({
      id: 'my-test-map',
      element: this.mapRef.nativeElement,
      apiKey: environment.mapsApiKey,
      config: {
        center: {
          lat: lat,
          lng: lng,
        },
        zoom: 15,
      },
    });

    // Adds marker for current pos
    await this.newMap.addMarker({
      coordinate: {
        lat: lat,
        lng: lng,
      },
      draggable: false,
    });
  }
}

I've seen some online videos that showed that I needed to add disableDefaultUI: true just below the zoom property, but I get the error: Object literal may only specify known properties, and 'disableDefaultUI' does not exist in type 'GoogleMapConfig'.

I am using:

"@ionic/angular": "^8.0.0",
"@capacitor/geolocation": "^7.1.0",
"@capacitor/google-maps": "^7.0.0",

Any suggestion on how to do this?

I have an angular + ionic + capacitor project where I want to show a map with a searchbar and a card, I am using google maps but I want to remove the UI controls, like the yellow guy for the streetview, the + and - for the zoom etc.

export class HomePage implements AfterViewInit {
  @ViewChild('map') mapRef!: ElementRef;
  newMap!: GoogleMap;

  async ngAfterViewInit() {
    await this.getCurrentLocation();
  }

  async getCurrentLocation() {
    try {
      const coordinates = await Geolocation.getCurrentPosition();
      const lat = coordinates.coords.latitude;
      const lng = coordinates.coords.longitude;

      await this.createMap(lat, lng);
    } catch (error) {
      console.error('Error in function getCurrentLocation', error);
    }
  }

  async createMap(lat: number, lng: number) {
    this.newMap = await GoogleMap.create({
      id: 'my-test-map',
      element: this.mapRef.nativeElement,
      apiKey: environment.mapsApiKey,
      config: {
        center: {
          lat: lat,
          lng: lng,
        },
        zoom: 15,
      },
    });

    // Adds marker for current pos
    await this.newMap.addMarker({
      coordinate: {
        lat: lat,
        lng: lng,
      },
      draggable: false,
    });
  }
}

I've seen some online videos that showed that I needed to add disableDefaultUI: true just below the zoom property, but I get the error: Object literal may only specify known properties, and 'disableDefaultUI' does not exist in type 'GoogleMapConfig'.

I am using:

"@ionic/angular": "^8.0.0",
"@capacitor/geolocation": "^7.1.0",
"@capacitor/google-maps": "^7.0.0",

Any suggestion on how to do this?

Share Improve this question asked 14 hours ago CroiccoCroicco 12811 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

After reviewing the official Capacitor documentation in the GitHub repository, it appears that the Ionic team left this property out for whatever reason they have.

You might consider submitting a feature request to see if they will include it. Alternatively, instead of using capacitor-google-maps, you could opt for the official Angular Google Maps component. It's significantly better than the Ionic plugin, offering all features and being mobile-friendly. The disableDefaultUI property is included there.

https://github/angular/components/blob/main/src/google-maps/README.md

发布评论

评论列表(0)

  1. 暂无评论