autoreleasepool行上的错误

时间:2016-04-14 12:21:19

标签: objective-c xcode

我刚开始使用目标c,我在一本书中有一个例子,我应该遵循,但是我遇到了错误,我不知道如何解决它。 here is the problem

编辑:好的,我把两个缺失的括号{}放在正确的位置,但现在又有两个错误!

this is the image

1 个答案:

答案 0 :(得分:0)

更仔细地阅读本书; - )

{之前的@autoreleasepool 前面的} 以及return 0行之前的右大括号public void showMap() { mapFragment = (SupportMapFragment)getChildFragmentManager().findFragmentById(R.id.map); if (map == null) { map = mapFragment.getMap(); } // Enable Zoom map.getUiSettings().setZoomGesturesEnabled(true); //set Map TYPE map.setMapType(GoogleMap.MAP_TYPE_NORMAL); //enable Current location Button map.setMyLocationEnabled(true); LocationManager locationManager = (LocationManager)getActivity().getSystemService(getActivity().LOCATION_SERVICE); Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, true); if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } Location location = locationManager.getLastKnownLocation(bestProvider); if (location != null) { onLocationChanged(location); } locationManager.requestLocationUpdates(bestProvider, 2000, 0, this); } @Override public void onLocationChanged(Location location) { latitude= location.getLatitude(); longitude=location.getLongitude(); LatLng loc = new LatLng(latitude, longitude); if (marker!=null){ marker.remove(); } marker= map.addMarker(new MarkerOptions().position(loc).title("Sparx IT Solutions")); map.moveCamera(CameraUpdateFactory.newLatLng(loc)); map.animateCamera(CameraUpdateFactory.newLatLngZoom(loc, 16.0f)); } @Override public void onProviderDisabled(String provider) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); Toast.makeText(getActivity().getBaseContext(), "Gps is turned off!!", Toast.LENGTH_SHORT).show(); } @Override public void onProviderEnabled(String provider) { Toast.makeText(getActivity().getBaseContext(), "Gps is turned on!! ", Toast.LENGTH_SHORT).show(); }