Google Maps API v2 not working

前端 未结 4 1522
失恋的感觉
失恋的感觉 2021-02-15 11:50

I am trying to build an application using Google Maps API v2 but the thing is, the application keeps giving me force closes although i followed all the required instructions.

4条回答
  •  忘掉有多难
    2021-02-15 12:35

    I found you missed several things in your code.

    Answer 1: Your GPSonMAP.java must be modified like below;

    public class GPSonMap extends android.support.v4.app.FragmentActivity{
     GoogleMap googlemap;  // "MapView map;" is wrong
     //MapController controller;  ==> it was depreciated.
     LocationManager locationManager;
     LocationListener listener;
     PendingIntent pendingIntent ;
     Criteria criteria;
     //MapOverlay overlay; ==> it was depreciated.
     SupportMapFragment fm; // add this
    
    
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.map);
            Log.d("", "entered");
    
    
        //map = (MapView)findViewById(R.id.mapView); ==> delete it.
    
         fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapView);
         googleMap = fm.getMap();
        }
    
    
    }
    

    After modifying the above, press "Ctrl + Shft + (alphabet) O " and some required classes will be imported.

    Answer 2: Your xml file in layout must be modified like below;

    
    

    Your MainActivity is not MapsActivity, but GPSonMap.

    Answer 3: Your Manifest file does not match your package name with the described package name in the manifest file. Please match the package name with the same one.

    Modify "com.example.example" to your package name.

    After copying and pasting some codes, you MUST check the package name and class name at least.

提交回复
热议问题