Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set default location and Zoom level for google map api v2?

When my map shows, it always start at a fixed location (near Africa).

Then, I use the following code to center the map to the location I want.

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(loc.getLatitude(), loc.getLongitude()), 14.0f)); 

My question is that could I set a default location and zoom level before the map shows?

Because I don't want my users to see the animation at the beginning.

Thanks.

like image 489
dong221 Avatar asked Jan 04 '13 12:01

dong221


People also ask

How do I change the default zoom on Google Maps?

You can change the zoom level of the map using simple steps. Step 1 Go to Add or Edit Map page . Step 2 Select 'Default zoom level' in the 'Map Information section'. Step 3 click save map and see the changes.

How do I zoom in Google Maps API?

Users can zoom the map by clicking the zoom controls. They can also zoom and pan by using two-finger movements on the map for touchscreen devices.

How do I change the max zoom level in Google Maps?

Setting up the minimum or maximum Zoom value for Google Maps can be done by adding the shortcode attribute with Store Locator Shortcode. Furthermore, the maximum value of Google Maps Zoom level is 22. Therefore, the defined maximum value must be below or equal to 22, which is the default.

How do I fix Google Maps zoom?

To fix Google maps zooming problems, for Google maps default zoom you want to know how to change the zoom level on Google Maps. You can change the zoom level by going to the Edit map page and then selecting 'default zoom level' in the map information section and then clicking save map.


2 Answers

you can use this to zoom directly without the animation :

map.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx) , 14.0f) ); 
like image 166
Moh Sakkijha Avatar answered Oct 09 '22 08:10

Moh Sakkijha


Take a look at the documentation here:

https://developers.google.com/maps/documentation/android-api/map#configure_initial_state

The way to do it is slightly different depending on whether you are adding the map via XML or programmatically. If you are using XML, you can do it as follows:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"   xmlns:map="http://schemas.android.com/apk/res-auto"   android:id="@+id/map"   android:layout_width="match_parent"   android:layout_height="match_parent"   class="com.google.android.gms.maps.SupportMapFragment"   map:cameraBearing="112.5"   map:cameraTargetLat="-33.796923"   map:cameraTargetLng="150.922433"   map:cameraTilt="30"   map:cameraZoom="13"/> 

If you are doing it programmatically, you can do the following:

CameraPosition cameraPosition = new CameraPosition.Builder()     .target(new LatLng(-33, 150))     .zoom(13)     .build(); MapFragment.newInstance(new GoogleMapOptions()     .camera(camera)); 
like image 37
Anthony Avatar answered Oct 09 '22 09:10

Anthony