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

后端 未结 5 1993
予麋鹿
予麋鹿 2020-12-02 07:13

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.a         


        
5条回答
  •  情深已故
    2020-12-02 07:38

    Just in case you want to load Google Map at any initial Location programmatically then you can use this piece of code,

    FragmentManager fm = getFragmentManager(); // getChildFragmentManager inside fragments.
    CameraPosition cp = new CameraPosition.Builder()
                        .target(initialLatLng) // your initial co-ordinates here. like, LatLng initialLatLng
                        .zoom(zoom_level)
                        .build();
    SupportMapFragment mapFragment = SupportMapFragment.newInstance(new GoogleMapOptions().camera(cp));
    fm.beginTransaction().replace(R.id.rl_map, mapFragment).commit();
    

    Add this piece of code for layout

    
    

    This will load GoogleMap at particular Location directly i.e, initialLatLng.

提交回复
热议问题