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 8987437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:47:33+00:00 2026-06-15T21:47:33+00:00

I am using Google Map API v2 in my application to show Maps. I

  • 0

I am using Google Map API v2 in my application to show Maps.

I have followed all the steps, that is to be followed to enable Google Map in my application.

public class PinLocationOnMapView extends FragmentActivity {

    private double mLatitude = 0.0, mLongitude = 0.0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SupportMapFragment fragment = SupportMapFragment.newInstance();
        getSupportFragmentManager().beginTransaction()
                .add(android.R.id.content, fragment).commit();
    }
}

If I use this code, it shows me map, but if I provide my latitude/longitude values, map tiles does not load, and I see only white tiles.

Following is the code written in onCreate() of above class:

 if (getIntent().getExtras() != null) {
            final Bundle bundle = getIntent().getBundleExtra("LOCATION");
            mLatitude = bundle.getDouble("LATITUDE");
            mLongitude = bundle.getDouble("LONGITUDE");
        } else {
            finish();
        }

        GoogleMapOptions options = new GoogleMapOptions();
        LatLng latLng = new LatLng(mLatitude, mLongitude);
        CameraPosition cameraPosition;// = new CameraPosition(latLng, 0, 0, 0);
        cameraPosition = CameraPosition.fromLatLngZoom(latLng, (float) 14.0);

        options.mapType(GoogleMap.MAP_TYPE_SATELLITE).camera(cameraPosition)
                .zoomControlsEnabled(true).zoomGesturesEnabled(true);

        SupportMapFragment fragment = SupportMapFragment.newInstance(options);
        getSupportFragmentManager().beginTransaction()
                .add(android.R.id.content, fragment).commit(); 

Also, I have a list of lat/long values. I want to show them on MapFragment, how to show multiple markers on MapFragment?

I tried with MapView and ItemizedOverlay, but it didn’t work for me. I believe I have correctly created the SHA1 key to get the API key, because if that was wrong, I could not see map using MapFragment as well, but I can see that if I don’t pass the lat/log value.

  • 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-15T21:47:35+00:00Added an answer on June 15, 2026 at 9:47 pm

    I do it like this to show car positions on the map with markers of different colors:

        private void addMarkersToMap() {
        mMap.clear();
        for (int i = 0; i < Cars.size(); i++) {         
                LatLng ll = new LatLng(Cars.get(i).getPos().getLat(), Cars.get(i).getPos().getLon());
                BitmapDescriptor bitmapMarker;
                switch (Cars.get(i).getState()) {
                case 0:
                    bitmapMarker = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED);
                    Log.i(TAG, "RED");
                    break;
                case 1:
                    bitmapMarker = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN);
                    Log.i(TAG, "GREEN");
                    break;
                case 2:
                    bitmapMarker = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE);
                    Log.i(TAG, "ORANGE");
                    break;
                default:
                    bitmapMarker = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED);
                    Log.i(TAG, "DEFAULT");
                    break;
                }               
                mMarkers.add(mMap.addMarker(new MarkerOptions().position(ll).title(Cars.get(i).getName())
                        .snippet(getStateString(Cars.get(i).getState())).icon(bitmapMarker)));
    
                Log.i(TAG,"Car number "+i+"  was added " +mMarkers.get(mMarkers.size()-1).getId());
            }
        }
    
    }
    

    Cars is an ArrayList of custom objects and mMarkers is an ArrayList of markers.

    Note : You can show map in fragment like this:

    private GoogleMap mMap;
    ....
    
    private void setUpMapIfNeeded() {
        // 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.map)).getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }
    
    
    
    
    private void setUpMap() {
        // Hide the zoom controls as the button panel will cover it.
        mMap.getUiSettings().setZoomControlsEnabled(false);
    
        // Add lots of markers to the map.
        addMarkersToMap();
    
        // Setting an info window adapter allows us to change the both the
        // contents and look of the
        // info window.
        mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
    
        // Set listeners for marker events. See the bottom of this class for
        // their behavior.
        mMap.setOnMarkerClickListener(this);
        mMap.setOnInfoWindowClickListener(this);
        mMap.setOnMarkerDragListener(this);
    
        // Pan to see all markers in view.
        // Cannot zoom to bounds until the map has a size.
        final View mapView = getSupportFragmentManager().findFragmentById(R.id.map).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.Builder bld = new LatLngBounds.Builder();
        for (int i = 0; i < mAvailableCars.size(); i++) {           
                LatLng ll = new LatLng(Cars.get(i).getPos().getLat(), Cars.get(i).getPos().getLon());
                bld.include(ll);            
        }
        LatLngBounds bounds = bld.build();          
        mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 70));
                    mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
    
                }
            });
        }
    } 
    

    And just call setUpMapIfNeeded() in onCreate()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a map application in Android. I'm using Google maps API to show
I have an application where I'm using the Google Map API to display markers
I have the following problem. I have embedded a map using Google Maps' API.
I have made my own map using the google maps api. It is a
I'm working on an advanced map application in Google Maps API V3. I'm using
I have made a mobile application that use Google static maps to get map
I have a web application that is using the below Google Maps open source
Im trying to develop an application that should show a map using the Google
I am working on an application that is using the google maps javascript API
I have a map with multiple markers of companies using google maps API v3.

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.