The Void Ionic type does not have the specified property available

Struggling to load markers when the button is clicked to find nearby gyms. Despite loading the map to my location upon click, no markers are displayed and an error indicating that then does not exist on type 'void' within IonViewDidLoad.

gyms.html

<ion-header>

  <ion-navbar>
    <ion-title>Gyms Nearby</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <ion-buttons start>
    <button ion-button round full (click)="gymMap()">Find Gyms Near Me</button>
  </ion-buttons>

  <div #map id="map"> </div>

  <div id="resultList">
      <ion-list>

        <ion-card>
           <ion-item ng-if = "places" >
           Places Found: {{places?.length}}
          </ion-item>
         </ion-card>  

        <ion-card id="result"> </ion-card>
          <button ion-item *ngFor = "let place of places; let i = index">
           {{place.name}} + <br/> {{place.vicinity}} <br /> Average Rating: {{place.rating}}
          </button>
        </ion-list>
  </div>

</ion-content>

gyms.ts

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Geolocation } from '@ionic-native/geolocation';

declare var google;


@Component({
  selector: 'page-gyms',
  templateUrl: 'gyms.html',
})
export class GymsPage {
  map: any;
  places: Array<any>;  

  constructor(public navCtrl: NavController, public navParams: NavParams, public geolocation:Geolocation) {
  }

  ionViewDidLoad() {
    this.gymMap().then((results : Array <any>)=>{
      for (let i=0; i< results.length; i++){
        this.createMarker(results[i]);
      }
      this.places = results;
    }, (status)=>console.log(status));
  }

  gymMap(){
    this.geolocation.getCurrentPosition().then((position) =>{
      let currentLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

      let mapOptions = {
        zoom: 12,
        center: currentLocation,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }

      this.map = new google.maps.Map(document.getElementById("map"),mapOptions);

      let service = new google.maps.places.PlacesService(this.map);
      let request = {
        location : currentLocation,
        radius : '10000',
        rankBy : google.maps.places.DISTANCE,
        type: ['gym'],
      };

      return new Promise((resolve,reject) =>{
        service.nearbySearch(request,(results,status)=>{
          if (status == google.maps.places.PlacesServiceStatus.OK){
            resolve(results);
          }else{
            reject(results);
          }
        });
      }); 

    }); 

  }//end of gymMap

  createMarker(place){
    let marker = new google.maps.Marker({
      map: this.map,
      animation: google.maps.Animation.DROP,
      position: place.geometry.location,
      title: place.name,
    });

    google.maps.event.addListener(marker, 'click', ()=>{
      let infowindow = new google.maps.InfoWindow({
        content: place.name 
      });
      infowindow.open(this.map,marker);
    })
  }//end of createMarker


}//end of GymsPage

Answer №1

To implement the use of `fat arrow` functions, follow the examples provided below.

First instance:

return new Promise((resolve,reject)=> {
        service.nearbySearch(request, (results,status)=> {
          if (status == google.maps.places.PlacesServiceStatus.OK){
            resolve(results);
          } else{
            reject(results);
          }
        });
      });

Second scenario:

google.maps.event.addListener(marker, 'click', ()=> {
      let infowindow = new google.maps.InfoWindow({
        content: place.name 
      });
      infowindow.open(this.map,marker);
    })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to find information in a multi-page table?

I've implemented a table with pagination and search functionality to look up data within the table. However, currently the search only works within the current page of the table rather than searching the entire dataset. Is there a way to modify the se ...

When utilizing Ionic Firebase, the user profile saved in the sidemenu is stored using the Events class. However, the saved profile disappears as soon as

Hello there. I am currently working on displaying my user's information in the sidemenu, and after some research, I found that using the Events class might solve this issue. However, I have noticed that the data saved in subscribe gets destroyed whene ...

An optional field has been identified as ng-invalid

In my set-up, I have created a form group using reactive forms. this.transactionForm = fb.group ({ 'location': [null, Validators.required], 'shopper': [null], 'giftMessage': [null], 'retailPrice& ...

There is no definition for Angular 4 Material stepper tags

After thoroughly studying the Angular Material stepper documentation, I encountered an issue when attempting to integrate the HTML Material stepper tag into my Angular application. The error message stated that it's not a known element. HTML: <ma ...

Issues with Firebase Cloud Messaging functionality in Angular 10 when in production mode

Error: Issue: The default service worker registration has failed. ServiceWorker script at https://xxxxxx/firebase-messaging-sw.js for scope https://xxxxxxxx/firebase-cloud-messaging-push-scope encountered an error during installation. (messaging/failed-ser ...

Error: Angular 6 resolve consistently returns undefined

Seeking to implement my service for retrieving values from the database server and displaying them onscreen, I have set up a resolver for the service since the database can be slow at times. However, no matter what I try, the data received through this.ro ...

Having trouble resolving all parameters for 'Router' in Angular 2 testing with Router

Currently, I am in the process of testing a component that has Router injected in the constructor (TypeScript): constructor( private _router: Router, private dispatcher: Observer<Action>, fb: FormBuilder ) { ... } Here are the test cases ...

Having difficulty subscribing to multiple observables simultaneously using withLatestFrom

I am facing an issue where I have three observables and need to pass their values to a service as parameters. I attempted to do this using WithLatestFrom(), but it works fine only when all values are observables. this.payment$.pipe( withLatestFrom(this.fir ...

Encountered Angular error: Maximum call stack size exceeded. Command execution ended with exit code 1

What is the cause of this error? I am executing $ nx build frontend --configuration=production --skip-nx-cache it is invoked from it > ng run frontend:build:production and the error occurs, what could be causing this issue? ERROR in Maximum call stac ...

Display of Navigation Bar in Angular is Not Proper

Currently diving into the world of Angular, I've encountered an issue with a material menu that isn't displaying correctly. The expected outcome based on my code should resemble this image: https://i.stack.imgur.com/z70Aq.png This snippet showc ...

What could be causing TypeORM to create an additional column in the query

Why does this TypeORM query produce the following result? const result6 = await getConnection() .createQueryBuilder() .select('actor.name') .from(Actor,'actor') .innerJoin('actor.castings',&apos ...

The event listener for 'end' is not executing in a Node.js Firebase and Nylas Express application

I am currently working on setting up webhooks with Nylas. In their provided example, there is a middleware code that I am implementing in my TypeScript project using Firebase as the endpoint. When testing locally with ngrok, the middleware functions prop ...

Utilizing regular expressions to search through a .md file in JavaScript/TS and returning null

I am currently using fs in JavaScript to read through a changelog.MD file. Here is the code snippet: const readFile = async (fileName: string) => { return promisify(fs.readFile)(filePath, 'utf8'); } Now I am reading my .md file with this fu ...

The @Input default value is being replaced by `undefined` within the testing environment

Within my component, I have the following input: @Input() someThing: string = 'm'; // default value When testing, I defined it as follows: @Component({ selector: 'app-test-wrapper-component', template: ` <app-my-component so ...

How can we effectively display the cookie value within the template by utilizing observables and selectors in conjunction with the ngx-cookie-service library?

I'm wondering if there's a seamless approach to leverage observables for dynamically retrieving a cookie value, essentially creating a "reactive" cookie. Although typical solutions involve utilizing this.cookieService.get("cookieName") within ser ...

What is the best way to declare a minimum and maximum date in HTML as the current date?

I have a question regarding setting the min/max date for a date input in my Angular 6 project. How can I ensure that only dates up to the current date are enabled? So far, I have attempted to initialize a new Date object in the ngOnInit function and set t ...

Encountering an issue during the installation of Angular CLI

I am encountering an error while attempting to install angular/cli on my 64-bit Windows 10 machine. The specific error I am receiving is as follows: npm ERR! code ENOGIT npm ERR! Error while executing: npm ERR! undefined ls-remote -h -t ssh://<a href=" ...

Top Tip for Preventing Angular Version Compatibility Issues

Here is an illustration that delves into my inquiry ----> Version Conflict The dilemma arises when my product has a dependency on a node package, which in turn relies on a specific version of Angular, denoted as version #y. However, my product itself ...

Detecting the State of the Keyboard in Ionic 2

Seeking an easy way to determine if the mobile device keyboard has been opened or closed using Ionic2 and Angular2. Is there a 'keyboard-open' or 'keyboard-close' class that Ionic sends to the body/html? ...

Having trouble accessing the theme in a styled component with @emotion/styled

https://i.stack.imgur.com/zHLON.png I've been using @emotion/react for theming and successfully injected the theme into it. I can access the theme using useTheme within components, but I'm facing some difficulties in accessing the theme within s ...