Skip to main content

Location Wikipedia

|

Landmarks can include Wikipedia data such as title, image title, URL, description, page summary, language, and more. To demonstrate how to retrieve Wikipedia information, we introduce the ExternalInfo class, which handles Wikipedia data.

Objects of type ExternalInfo are provided by the ExternalInfoService class.

Check if Wikipedia data is available

Use the static hasWikiInfo method of the ExternalInfoService class to check if a landmark has wikipedia data available:

import { ExternalInfoService, Landmark } from '@magiclane/maps-sdk';

const hasExternalInfo: boolean = ExternalInfoService.hasWikiInfo(landmark);
warning

Make sure the wikipedia related fields from the extraInfo property of the Landmark object are not tempered with if changes are made to the landmark data.

ExternalInfo class

This class provides Wikipedia information for a landmark. An ExternalInfo object is obtained using the static method requestWikiInfo of the ExternalInfoService class.

import { ExternalInfoService, GemError, ExternalInfo, Landmark } from '@magiclane/maps-sdk';

const requestListener = ExternalInfoService.requestWikiInfo(
landmark,
(err: GemError, externalInfo: ExternalInfo | null) => {
if (err !== GemError.success) {
console.log(`Error getting wiki info: ${err}`);
return;
}

// Data about the page
const title: string = externalInfo!.wikiPageTitle;
const content: string = externalInfo!.wikiPageDescription;
const language: string = externalInfo!.wikiPageLanguage;
const pageUrl: string = externalInfo!.wikiPageUrl;
}
);

The requestWikiInfo returns a progress listener which can be used to cancel the request using the cancelWikiInfo method of the ExternalInfoService class.

note

Wikipedia data is provided in the language specified in SDKSettings. Learn more about setting the SDK language here.

The method provides a result based on the outcome of the operation:

  • On success returns GemError.success and a non-null ExternalInfo object.
  • On failure returns a null ExternalInfo object and one of the following GemError values:
    • GemError.invalidInput : The specified landmark does not contain Wikipedia-related information.
    • GemError.connection : No internet connection is available.
    • GemError.notFound : Wikipedia information could not be retrieved for the given landmark.
    • GemError.general : An unspecified error occurred.

Wikipedia image data

The ExternalInfo class provides the following details regarding images:

import { ExternalInfo } from '@magiclane/maps-sdk';

const imgCount: number = externalInfo.wikiImagesCount;
const imageUrl: string = externalInfo.getWikiImageUrl(0);
const imageDescription: string = externalInfo.getWikiImageDescription(0);
const imageTitle: string = externalInfo.getWikiImageTitle(0);

Detailed informations about an image can be retrieved using the requestWikiImageInfo method:

import { GemError } from '@magiclane/maps-sdk';

const imageInfoListener = externalInfo.requestWikiImageInfo(
0, // imageIndex
(error: GemError, imageInfo: string | null) => {
if (error !== GemError.success) {
console.log(`Error getting wiki image info: ${error}`);
return;
}

// Do something with image info...
}
);

The requestWikiImageInfo method return a progress listener which can be used to cancel the request using the cancelWikiImageInfoRequest method.