Welcome back.
In this video we're going to learn how to configure the initial camera position in Google Maps.
When using Google Maps, we need to set and configure the initial camera position, which determines
where the map will be centered and at what zoom level when it first loads.
If we load our application, it loads at the equator, and at this zoom level we can make zoom at what
whatever we want.
But the initial loading is at this zoom level and at this position.
Let me create here Singapore coordinates the latitude and longitude.
Here you can notice that Singapore is of type lat long.
The lat long represents a geographic location with latitude and longitude.
If we go to the latitude declaration, we can notice that the latitude is of type double and the longitude
is of type double.
So this type of variables represent a geographic location with latitude and longitude.
We can set the let 1.35 and the long longitude 103.87.
Okay.
Now let me determine the zoom level and the camera position val camera position state equals to remember
camera position state set the position equals to camera position dot from lat long zoom.
We need to set the latitude which is the Singapore and the zoom level which is ten F.
Let me explain before running the camera position.
If we click Ctrl and left mouse defines the viewport of the map, including the target, the target
which is the.
It's of type lat, long latitude and longitude.
Zoom level float between 0 and 21.
Tilt angle of a view 0 to 90 degrees and burning 0 to 360 degrees.
The remember camera position state a composable function that creates and remembers the camera state.
Okay, so here we have the longitude and latitude zoom Singapore and ten F.
This is the starting point.
This is the lat long zoom ten F zoom okay.
In order to assign this attribute.
and this parameter to the Google map.
Here we need to set the camera position state to the camera position state variable that we created
before.
Okay, so what we did here, we created two things.
The first one is the Singapore which is the lat long variable latitude and longitude.
This is for Singapore and the camera position state.
This determines the camera position and the zoom level of our Google map.
The first thing is centered Singapore and the zoom level is ten F.
In order to use this zoom and camera position state, we use the camera position state parameter and
assign it to the variable that we just created here.
Let me stop the app, run it again, and you can notice that we are centered.
Our map is centered in Singapore and the zoom level is set it to ten.
Okay.
This is our application.
This is how we set the initial state, the initial position and the initial zoom level of our Google
map.
Okay.
You can set it to for example, five F.
Let me check it again.
You can notice that we are zooming out.
If we increase it to like 20 for example run it again.
Here we zoomed in.
Okay.
Scroll up zoom out.
We can notice that we are on Singapore.
Okay.
So this is how we define the initial state of our Google map.
Also we can define other variables.
Let me show you here.
Let me comment this and let me create here.
Val camera position I can make it as my camera position.
My camera position equals to remember.
And here create a new camera position variable having four parameters.
The target lat long which is Singapore.
The zoom level equals to 15 f, the blurring equals to 45 f and tilt equals to 30 f.
Import.
Remember we have the target Singapore zoom 15 f close up view blurring 45 F rotated 45 degrees.
Tilt 30 degrees angle view.
Let me remove those parameters.
Maybe you didn't recognize them.
And this is good okay.
Now let's move to that camera position state.
And here use the remember camera position state and set the position to my camera position.
Run again and here we go.
You can notice that we are on uh Singapore position.
We have 15 f close up view.
You can notice the streets are visible 40 F rotated 45 degrees from north.
You can notice that north, uh, needle is 45 degrees tilted and bearing 30 degrees 30 degrees angle
view.
If you move up, you can notice that we are tilted 30 degrees.
Okay.
This is our initial camera position.
We configure, uh, some basic things like zoom, tilt blurring.
And the most important thing which is the initial position.