volga-volga / react-native-yamap

React Native Yandex Maps | Яндекс Карты | Yandex.MapKit implementation for react native | YandexMaps
144 stars 80 forks source link

GeoSuggestions #256

Closed alen-s closed 9 months ago

alen-s commented 9 months ago

I am using this code to get

import { Suggest } from 'react-native-yamap';

const find = async (query: string, options?: SuggestOptions) => {
  const suggestionsWithCoards = await Suggest.suggestWithCoords(query, options);

  // suggestionsWithCoards = [{
  //   subtitle: "Москва, Россия"
  //   title: "улица Льва Толстого, 16"
  //   lat: 55.733974
  //   lon: 37.587093
  //   uri: "ymapsbm1://geo?ll=37.587093%2C55.733974&spn=0.001000%2C0.001000&text=%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D1%8F%2C%20%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0%2C%20%D1%83%D0%BB%D0%B8%D1%86%D0%B0%20%D0%9B%D1%8C%D0%B2%D0%B0%20%D0%A2%D0%BE%D0%BB%D1%81%D1%82%D0%BE%D0%B3%D0%BE%2C%2016"
  // }, ...]

  // After the search session is finished
  Suggest.reset();
}

But the uri I am getting doesn't include lat and lon, the uri looks like this.

suggestWithCoords [
  {
    "subtitle": "Yerevan",
    "uri": "ymapsbm1://geo?data=CgoxNzIxMTAzMDgwEiZBcm1lbmlhLCBZZXJldmFuLCBTb3NlIFN0cmVldCAxc3QgTGFuZSIKDQwBMkIVlscgQg,,",
    "title": "Sose Street 1st Lane"
  },
]

Can anybody help me with this?

cc: @segrey-profi

segrey-profi commented 9 months ago

Sorry but that's what Yandex returns in response to your particular request. The data here is (poorly?) base64 encoded and it doesn't contain lat or lon, just a string with address "1721103080 &Armenia, Yerevan, Sose Street 1st Lane" (you can check it e.g. here: https://www.base64decode.org/)

alen-s commented 9 months ago

Thanks for the answer @segrey-profi, but shouldn't it return the lat and lon like provided in the sample?

segrey-profi commented 9 months ago

Well, it seems this library doesn't work with such type of response from Yandex. Maybe you should make a feature request to the author (or implement it yourself and make a pull request :))

alen-s commented 9 months ago

We can use Geocoder.reverseGeocode() method for suggestions, like this.

const suggestions = await Geocoder.reverseGeocode(
  query,
  'house',
  7,
  0,
  'en_US',
);
suggestions.response.GeoObjectCollection.featureMember,