Skip to content

Geocoder (Geocoding Service)

Create and manage geocoding services for address and landmark search.

Constructor

ts
new ge3d.Geocoder(options?: GeocoderOptions): Geocoder

Parameters (GeocoderOptions)

ParameterTypeDefaultDescription
keyStringdefaultTokenAPI key for geocoding service
coreCore-Map core instance (required for camera height calculation)

Properties

PropertyTypeDescription
optionsObjectConfiguration options
keyStringAPI key for geocoding service
coreCoreMap core instance

Methods

MethodParametersReturn ValueDescription
geocode(query: string)Promise<GeocoderResult[]>Search for addresses and landmarks

GeocoderResult

PropertyTypeDescription
displayNameStringDisplay name of the location
destinationCesium.Cartesian33D coordinates of the location
dataObjectRaw data from the geocoding service

Usage Example

javascript
// Create map core
const core = new ge3d.Core("cesiumContainer", {
  scene: {
    center: { lat: 39.9087, lng: 116.3975, alt: 20000000 },
    geocoder: true
  },
  baseImages: [
    {
      id: 'tdtLayerId',
      name: "Tianditu Imagery",
      type: "tdt",
      layer: "img_d",
      show: true
    }
  ]
});

// Create geocoder instance
const geocoder = new ge3d.Geocoder({
  // core: core // Optional, used for camera height calculation
});

// Search for a location
const data = geocoder.geocode('Riyadh');

// Handle the result
data.then((results) => {
  console.log(results);
  if (results.length > 0) {
    // Fly to the first result
    core.flyToPoint(results[0].destination);
  }
});

Notes

  1. The geocoder uses OpenStreetMap's Nominatim service for geocoding
  2. Results are automatically converted from WGS84 to the correct coordinate system
  3. Camera height is automatically calculated based on current view or defaults to 3000 meters
  4. The geocoder can be integrated into the map's built-in geocoder widget by setting geocoder: true in scene options
  5. Results include both display information and raw data from the geocoding service