But when i want to reach getLat and getLong variable from any function - or outside this.http.get()- that variables give undefined. What should i do? I tried static, const, global, var declare etc.
Adjust your expectations, for this is the way things are. Your intuition that asynchronous programming is involved is spot-on, but if you view this as a “problem”, you’re in for a lot of frustration.
It’s hard to give specific recommendations without knowing that you’re really trying to achieve with getLat - for example, if you’re trying to reference them from a template, then the AsyncPipe is a tool you might like.
In general, though, you need to incorporate in your designs the fact that Ionic applications, like most modern web apps, tend to prioritize responsiveness over predictability. The code inside your subscribe block will be executed when the underlying network request returns. Nothing outside that block has any clue when that will be unless you explicitly make the effort to tell it, and frequently that effort isn’t really worth it.
If you’re using this information to display a marker on a map, for example, do the things required to spawn the marker inside the subscribe block, so the user sees “no marker” and then “marker where it is supposed to be”. If you’re displaying it as text, think about a placeholder such as “loading…”. If the whole page simply can’t display at all until this data comes in, then think about popping a loading overlay or investigating route resolvers.