Answer the question
In order to leave comments, you need to log in
How to add your coordinates to the function call (with ymaps.ready )?
There is a main js:
import getUserLocation from './getLocation';
import addMap from './addMap';
const userLocation = getUserLocation();
/* eslint-disable */
ymaps.ready(addMap(53.9000, 27.5667));
/* eslint-enable */
export default async function getUserLocation() {
return fetch(`https://ipinfo.io/json?token=${токен}`).then((response) => response.json());
}
export default function initMap(latitude, longitude) {
/* eslint-disable */
new ymaps.Map('map', {
center: [latitude, longitude],
zoom: 15,
});
/* eslint-enable */
}
Answer the question
In order to leave comments, you need to log in
1) Create a global maps object:
import getUserLocation from './getLocation';
import addMap from './addMap';
let maps;
ymaps.ready(function() {
maps = new ymaps.Map("map", {
center: [55.76, 37.64],
zoom: 2
});
getUserLocation().then((lat, lng) => maps.setCenter([55.76, 37.64]));
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question