U
U
unlik2018-04-05 19:56:42
JavaScript
unlik, 2018-04-05 19:56:42

How to use the data from this script?

There is a script that determines the coordinates and city of the user.

ymaps.ready()
  .then(() => ymaps.geolocation.get({autoReverseGeocode: false})
  .then(res => res.geoObjects.get(0).geometry.getCoordinates()))
  .then(ll => ($('#latlng').append(`Координаты: ${ll}`), ymaps.geocode(ll)))
  .then(res => res.geoObjects.get(0).getLocalities())
  .then(city => $('#city').append(`${city}`))
  .catch(err => $('#err').append(`Ошибка: ${err}`))

How can you use if else in this case?
If it's stupid to do that, it won't work.
if (city == 'Москва') {
 } else  {
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-04-06
@webinar

do console.log(city);it and see what's real. I understand there is an object, not a string

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question