ОШИБКА TypeError: null не является объектом (оценивает 'this._icon.imageSource. ios') - PullRequest
0 голосов
/ 21 января 2020

Я пытаюсь получить пользовательский значок маркера на карте. Я использовал nativescript- google-maps -sdk v ^ 2.9.1 и получаю следующую ошибку.

CONSOLE LOG file:///node_modules/@nativescript/core/image-source/image-source.js:306:0: fromResource() is deprecated. Use ImageSource.fromResourceSync() instead.
CONSOLE ERROR file:///node_modules/@angular/core/fesm5/core.js:4002:0: ERROR TypeError: null is not an object (evaluating 'this._icon.imageSource.ios')

код, добавленный для получения маркера на карте:

addMarker(mark, index): void {
    const marker = new Marker();
    marker.position = Position.positionFromLatLng(mark.latitude, mark.longitude);
    // marker.icon = this.ocean_pin; // default pin
    const is24 = (isIOS ? '_24' : '');
    marker.icon = 'https://www.iconsdb.com/icons/preview/red/map-marker-2-xxl.png';//'https://mob-app-assets.s3.eu-west-2.amazonaws.com/pin_ocean' + is24 + '.png'; // default pin
    this.mapView.addMarker(marker);
    this.mMarkers.push(marker); // to update marker pin when carousel swiped
  }

Ранее я использовал значок из активов, и он работал как шарм. Найдите приведенный ниже код, который работал для иконок из ресурсов.

import * as imageSource from 'tns-core-modules/image-source';
import { Image } from 'tns-core-modules/ui/image/image';


constructor() {
    super();
    this.buttonHeight = isAndroid ? 45 : 35;
    const is24 = (isIOS ? '_24' : '');
    this.ocean_pin = new Image();
    this.ocean_pin.src = '~assets/icons/pin_ocean' + is24 + '.png';
    this.ocean_pin.imageSource = imageSource.fromFile('~assets/icons/pin_ocean' + is24 + '.png');
    this.pink_pin = new Image();
    this.pink_pin.src = '~assets/icons/pin_pink' + is24 + '.png';
    this.pink_pin.imageSource = imageSource.fromFile('~assets/icons/pin_pink' + is24 + '.png');
  }

Я не знаю, что пошло не так. Но теперь это не работает для иконок из URL.

...