Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9173703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:37:46+00:00 2026-06-17T16:37:46+00:00

I am using new maps api. its working fine.. But when the device orientation

  • 0

I am using new maps api. its working fine..
But when the device orientation changes.. the map become unresponsive. i mean map doesn’t react to the user response.

This, problem doesn’t occurs when i embed the map fragment in the layout xml. but occurs only when i am trying to add the mapfragment in the layout container in the Activity’s onCreate.

Can anyone tell me the problem.

Here the way i am adding the map

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeActivity" >


<FrameLayout
    android:id="@+id/activity_home_fragment_container"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true">
</FrameLayout>

</RelativeLayout>

And in Activity’s oncreate

mMapFragment = new SupportMapFragment();
    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    transaction.add(R.id.activity_home_fragment_container, mMapFragment,
            "MAP_FRAGMENT");
    transaction.commit();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:37:47+00:00Added an answer on June 17, 2026 at 4:37 pm

    Use this in your layout:

    <LinearLayout
            android:id="@+id/map_container2"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_weight="35.22"
            android:orientation="horizontal" >
    
            <fragment
                android:id="@+id/map1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                class="com.google.android.gms.maps.SupportMapFragment"
                map:cameraTargetLat="40.72"
                map:cameraTargetLng="-74.00"
                map:cameraZoom="8" />
        </LinearLayout>
    

    And this code:

    onCreate{
       setUpMapIfNeeded();
    }
    
    private void setUpMapIfNeeded() {
            // TODO Auto-generated method stub
            // Do a null check to confirm that we have not already instantiated the map.
            if (mMap == null) {
                // Try to obtain the map from the SupportMapFragment.
                mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map1))
                        .getMap();
                // Check if we were successful in obtaining the map.
                if (mMap != null) {
                    setUpMap();
                }
            }
        }
    
    private void setUpMap() {
            // TODO Auto-generated method stub
             // Hide the zoom controls as the button panel will cover it.
            mUiSettings = mMap.getUiSettings();
     // Enables/disables zoom gestures (i.e., double tap, pinch & stretch).
            mMap.getUiSettings().setZoomGesturesEnabled(false);
    // Enables/disables scroll gestures (i.e. panning the map).
            mMap.getUiSettings().setScrollGesturesEnabled(false);
     // Enables/disables the compass (icon in the top left that indicates the orientation of the
            // map).
            mMap.getUiSettings().setCompassEnabled(false);
            // Add lots of markers to the map.
            addMarkersToMap();
    
            // Pan to see all markers in view.
            // Cannot zoom to bounds until the map has a size.
            final View mapView = getSupportFragmentManager().findFragmentById(R.id.map1).getView();
            if (mapView.getViewTreeObserver().isAlive()) {
                mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                    @SuppressLint("NewApi") // We check which build version we are using.
                    @Override
                    public void onGlobalLayout() {
                        LatLngBounds bounds = new LatLngBounds.Builder()
                                .include(WOODS)
                                .build();
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                          mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                        } else {
                          mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                        }
                        mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
                    }
                });
            }
        }
    
    private void addMarkersToMap() {
            // TODO Auto-generated method stub
             // Uses a colored icon.
            mWoods = mMap.addMarker(new MarkerOptions()
                    .position(WOODS)
                    .title("Woods")
                    .snippet("R. Quatá, 1016, Vila Olimpia - (11) 3849-6868")
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a map using the new(ish) v3 of the Google Maps API
I am working on Google map application using Google Maps JavaScript API V2 .
i am using the google maps API (v3). I just realized that a new
I am using google maps api to place markers on a map. The gps
I am using Google Maps V3 API and using its Geocoder to do reverse
I'm trying to port my application to the new Google Maps API v2, but
I'm using the Google Maps API (v3) on my website to show a map
Hi I've been using Google Maps API v3 and geocoder to display a map
I'm using the Google Maps API to plot several points on a map. However,
I have created a custom map using the Google Maps API v3. It's a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.