android Tab片段。地图没有显示

时间:2017-08-31 02:17:14

标签: android android-fragments google-maps-android-api-2

我的所有标签都正常工作,看起来地图正在尝试工作(我在左下方看到了Google徽标,但地图未呈现。

Phome

以下是我的片段活动:

public class BarberMapActivity extends Fragment implements 
OnMapReadyCallback{

    private GoogleMap mMap;

    public static BarberMapActivity newInstance() {
        BarberMapActivity fragment = new BarberMapActivity();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.barber_map_tab, null, false);
        SupportMapFragment mapFragment = (SupportMapFragment) this.getChildFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

        return view;
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(34.0052982, -83.9888499);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
 }

这是我的地图布局:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".shopResult.tabs.BarberMapActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />

1 个答案:

答案 0 :(得分:0)

您应该将SHA-1添加到您的Google开发者控制台中 google developer console