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.

The ExternalInfo class is part of the core SDK and can be instantiated directly to access external information services.

Check if Wikipedia data is available

Use the hasWikiInfo method of the ExternalInfo class to check if a landmark has Wikipedia data available:

val externalInfoService = ExternalInfo()
val hasExternalInfo = externalInfoService.hasWikiInfo(landmark)
danger

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

ExternalInfo class

This class provides Wikipedia information for a landmark. Create an instance of ExternalInfo and use the requestWikiInfo method to retrieve Wikipedia data.

val externalInfoService = ExternalInfo()

val wikipediaProgressListener = ProgressListener.create(
onStarted = {
// Show loading indicator
progressBar.visibility = View.VISIBLE
},

onCompleted = { errorCode, _ ->
progressBar.visibility = View.GONE

if (errorCode == GemError.NoError) {
// Success - access Wikipedia data
SdkCall.execute {
val title = externalInfoService.wikiPageTitle
val content = externalInfoService.wikiPageDescription
val language = externalInfoService.wikiPageLanguage
val pageUrl = externalInfoService.wikiPageURL

// Use the retrieved data
displayWikipediaInfo(title, content, language, pageUrl)
}
} else {
// Handle error
showDialog("Error getting wiki info: ${GemError.getMessage(errorCode)}")
}
},

postOnMain = true
)

SdkCall.execute {
externalInfoService.requestWikiInfo(landmark, wikipediaProgressListener)
}

The requestWikiInfo method triggers a progress listener that will be notified when the operation completes. You can cancel the request using the cancelWikiInfo method.

info

Wikipedia data is provided in the language specified in SdkSettings.

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

  • On success returns GemError.NoError and the Wikipedia data is available through the ExternalInfo properties.
  • On failure returns 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:

SdkCall.execute {
val imgCount = externalInfoService.wikiImagesCount
val imageUrl = externalInfoService.getWikiImageURL(0)
val imageDescription = externalInfoService.getWikiImageDescription(0)
val imageTitle = externalInfoService.getWikiImageTitle(0)
}

Requesting Wikipedia image content

You can request the actual image content using the requestWikiImage method:

val image = Image()
val externalInfoService = ExternalInfo()
val imageProgressListener = ProgressListener.create(
onCompleted = { errorCode, _ ->
if (errorCode == GemError.NoError) {
// Image loaded successfully
SdkCall.execute {
//val bitmap = image.asBitmap(width, height)
// Display the image
//imageView.setImageBitmap(bitmap)
}
}
},
postOnMain = true
)
externalInfoService.requestWikiImage(
imageProgressListener,
image,
nImageIdx = 0,
EExternalImageQuality.Medium
)

Wikipedia image information

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

val externalInfoService = ExternalInfo()
val result = GemString()
val imageInfoListener = ProgressListener.create(
onCompleted = { errorCode, _ ->
if (errorCode == GemError.NoError) {
// Image info retrieved successfully
val imageInfo = result.value// GemString result
// Process the image information
} else {
showDialog("Error getting wiki image info: ${GemError.getMessage(errorCode)}")
}
},
postOnMain = true
)
externalInfoService.requestWikiImageInfo(imageInfoListener, nImageIdx = 0, result)

Canceling requests

You can cancel various requests using the available cancel methods:

// Cancel main Wikipedia info request
externalInfoService.cancelWikiInfo()

// Cancel specific image content request
externalInfoService.cancelWikiImageContentRequest(imageProgressListener)

// Cancel specific image info request
externalInfoService.cancelWikiImageInfoRequest(imageInfoListener)