Native HTTP with Google Places photo API crashes


#1

I am trying to get Google Places photos, but when opening the page where this photo is fetched, the app crashes and closes. I can reopen the app, but when returning to the same page, it crashes again. Below is the relevant code, as well as the API for the place details which does work and uses the same native HTTP plugin.

Google Maps provider

plugin is loaded:

import { HTTP } from '@ionic-native/http';

constructor(
  public http: HTTP,
)

functions to get place details and place photo:

getPlaceDetails(placeId: string) {
  return new Promise((resolve) => {
    this.http.get(`https://maps.googleapis.com/maps/api/place/details/json?placeid=${placeId}&language=nl&key=${this.apiKey}`, {}, {}).then((response) => {
      let data = JSON.parse(response.data);
      resolve(data.result)
    });
  });
}

getPlacePhotoUrl(reference: string) {
  return new Promise((resolve) => {
    this.http.get(`https://maps.googleapis.com/maps/api/place/photo?maxwidth=1000&photoreference=${reference}&key=${this.apiKey}`, {}, {}).then((response) => {
      resolve(response);
    });
  });
}

On the page/component where these functions are called:

this.gmap.getPlaceDetails(this.navParams.data).then((place: any) => {
  this.place = place;
  if (place.photos) {
    if (place.photos[0].html_attributions) this.place.photoAttributions = place.photos[0].html_attributions;
    this.gmap.getPlacePhotoUrl(place.photos[0].photo_reference).then(photoUrl => this.place.photoUrl = photoUrl);
  }
});

When I remove the line where .getPlacePhotoUrl() is called, everything works fine. BTW, it worked when I used the angular http plugin, but using that plugin, I had issues with CORS on iPhone.

Environment info:

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.15.2
    ionic (Ionic CLI) : 3.15.2

global packages:

    cordova (Cordova CLI) : 7.0.1

local packages:

    @ionic/app-scripts : 3.0.1
    Cordova Platforms  : browser 4.1.0 ios 4.4.0
    Ionic Framework    : ionic-angular 3.8.0

System:

    ios-deploy : 1.9.1
    Node       : v6.10.0
    npm        : 5.4.2
    OS         : macOS High Sierra
    Xcode      : Xcode 9.0.1 Build version 9A1004