The Geocoder allows converting between coordinates and addresses.
Important: The API_KEY for the Geocoder is different from the Map API key. You must initialize both classes separately.
Initialization:
import { Geocoder } from 'react-native-yamap';
Geocoder.init('YOUR_GEOCODER_API_KEY');
Direct Geocoding:
Geocoder.geocode(geocode: Point, kind?: ObjectKind, results?: number, skip?: number, lang?: Lang)
Simplified Methods:
geoToAddress(geo: Point): Returns null or an Address object for the first suggestion.addressToGeo(address: string): Returns null or the coordinates { lat, lon } for the first suggestion.
Reverse Geocoding:
Geocoder.reverseGeocode(geocode: string, kind?: ObjectKind, results?: number, skip?: number, lang?: Lang, rspn?: 0 | 1, ll?: Point, spn?: [number, number], bbox?: [Point, Point])
import { Geocoder } from 'react-native-yamap';
Geocoder.init('API_KEY');
// Simplified usage
const address = await Geocoder.geoToAddress({ lat: 55.75, lon: 37.62 });
const coords = await Geocoder.addressToGeo('Москва, Красная площадь');