Android GoogleMap or SupportMapFragment - null pointer exception

前端 未结 8 2013
心在旅途
心在旅途 2021-02-10 10:51

In my app i showing google map version2 in a fragment. but i get Null pointer exception at

mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id

相关标签:
8条回答
  • 2021-02-10 11:19
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    
    if(map != null) {
             mMap.addMarker(new MarkerOptions() .position(new LatLng(xxxxxx,xxxxxx)) .title("Current Location")
             .icon(BitmapDescriptorFactory.fromResource(R.drawable.ball_pointer))
             .snippet("xxxxx"));
    }
    
    <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="xxxxxxxxxxxxxxxxxxxxxxxx" />
    

    place your google api key here. You get from google Read the documentation.

    0 讨论(0)
  • 2021-02-10 11:23

    try to change this:

    FragmentManager myFM = getActivity().getSupportFragmentManager();
    
    final SupportMapFragment myMAPF = (SupportMapFragment) myFM
                    .findFragmentById(R.id.map);
    
    0 讨论(0)
提交回复
热议问题