O
O
ortsuev332018-09-29 10:35:12
JavaScript
ortsuev33, 2018-09-29 10:35:12

I have created a map in one function, how can I access it in another function?

When the page starts, I create a map (hidden with coordinates by default), then when a change occurs in the address field, I take the value from the field and look through the geocoder, the point is that this is all happening in another function, how can I access the created instance again and add new label?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
ortsuev33, 2018-09-29
@ortsuev33

I solved the problem by declaring a variable outside the function, thereby making it global. And I changed the existing coordinates of the yandex maps using the object.setCenter function

myMap.setCenter([53, 53], 14, {
    checkZoomRange: true
});

T
TCloud, 2018-09-29
@OTCloud

Usually, when creating instances of an object, a variable is used through which the created object is accessed.
Fundamentals of Object-Oriented Programming

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question