JarodMS

Mobile App Development with Ionic, Angular, and More!

Menu
  • Home
  • Mobile Apps
  • About Me
  • Contact Me
  • Diary
Menu

Ionic – the platform was not ready when I was trying to get the location

Posted on April 21, 2020April 21, 2020 by Jarod

Background

On the home screen of my app, I display a list of location-based content. So when the app loads, I get the users’ location and then pass that to the backend to retrieve the relevant content. I had been developing and testing in the browser as well as my Android device and had never seen an issue.

When I installed the app on my iPhone, I started seeing inconsistent results. This was after I had accepted the prompt to allow the app to access location, so I knew I was at least in the code that tries to get the location.

  • Sometimes when the app would start, no data would be shown. I don’t want to show the user bad data if the location is not known.
  • Sometimes the correct data was shown. Ah, that meant I was getting the location, passing it to the backend, and retrieving the correct info.
  • I could start and stop the app quickly and get different results each time (that is, data or no data).

Troubleshooting

I added several alerts in various places including when I was receiving the location and when I was calling the backend to retrieve data. I noticed that sometimes I wouldn’t even be making the call to the backend.

I then added an alert inside app.component.ts under initializeApp() to check and make sure the platform was really ready.

This is when I noticed that my “platform is ready” alert was coming after the “get location” alert. Ugh! I was actually trying to get the location and retrieve the data before the platform was even ready! (Before the Geolocation plugin was ready.)

Resolution

For the main home screen I had in place, I did another check to make sure the platform was ready. If it was ready, then I would get the location and retrieve the backend data.

ngOnInit() {
  this.platform.ready().then(() => {
    this.getTheDataINeed(); // Gets location and retrieves data
  });
}

I had never seen this before…the fact that the platform was not ready when my code was ready to init a component. It makes sense on why this is, but since I hadn’t experienced it on my iPhone, it was a head-scratcher. 

It bit me this time (took up some time anyways) but it was a good learning experience.

Please follow:
error
Tweet
0

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Newsletter

Signup with your email address to receive news and updates.

Search

Recent Posts

  • Not able to call REST API on Android, but it works with iOS and Web App
  • Ionic – the platform was not ready when I was trying to get the location
  • My Dividend Meter
  • Angular app using Node, JSON server, NG-Bootstrap, and NgRx
  • LoadingController example showing “Loading…” message
  • Adding the Version Number in your app
  • PhoneGap Build – Config File
  • Example Angular 8 with NgRx and Redux DevTools
  • Update an Ionic4/Angular7 app to use Angular 8
  • Ionic 4 and Angular with PouchDB

Need Help?

I’m available for Ionic and Angular contract work. Contact me to get started.

My Links

All my apps on Google Play Store
All my apps on Apple App Store
GitHub
LinkedIn

Archives

  • October 2020
  • April 2020
  • March 2020
  • November 2019
  • October 2019
  • August 2019
  • November 2018
  • August 2018
  • July 2018

Categories

  • Angular
  • Beginner
  • Ionic
  • Ionic Component
  • PhoneGap Build
  • Uncategorized
  • Visual Notification

Available for Angular and Ionic freelance work including custom app development.

Tags

Angular AuthGuard component Custom Icon Firebase Font Awesome Geolocation Google Cloud Functions icons ionic3 Ionic4 iOS NgRx PhoneGap Build tabs VirtualScroll
© 2025 JarodMS | WordPress Theme by Superbthemes