Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android “类型中的方法不适用于参数”错误_Android_Google Maps - Fatal编程技术网

Android “类型中的方法不适用于参数”错误

Android “类型中的方法不适用于参数”错误,android,google-maps,Android,Google Maps,下面的代码应该跟踪用户的当前位置,但是updatePlacesthis;提供错误信息类型MainActivity.CustomMapFragment中的updatePlacesContext方法不适用于参数MainActivity.CustomMapFragment。我对这一切还很陌生,我不能理解这个错误。我怎样才能着手解决它呢 /** * A fragment that displays the map. */ public static class CustomMapFragment e

下面的代码应该跟踪用户的当前位置,但是updatePlacesthis;提供错误信息类型MainActivity.CustomMapFragment中的updatePlacesContext方法不适用于参数MainActivity.CustomMapFragment。我对这一切还很陌生,我不能理解这个错误。我怎样才能着手解决它呢

/**
 * A fragment that displays the map.
 */
public static class CustomMapFragment extends Fragment implements
        LocationListener {

    private MapView mapView;
    private GoogleMap map;
    private int userIcon, AedValidatedIcon, AedNotValidatedIcon;
    private LocationManager locMan;
    private Marker userMarker;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        // Icons
        userIcon = R.drawable.blue_point;
        AedValidatedIcon = R.drawable.yellow_point;
        AedNotValidatedIcon = R.drawable.red_point;

        // Inflate and return the layout
        View v = inflater.inflate(R.layout.map_fragment, container, false);
        mapView = (MapView) v.findViewById(R.id.mapView);
        mapView.onCreate(savedInstanceState);
        mapView.onResume();// needed to get the map to display immediately

        map = mapView.getMap();
        map.getUiSettings().setAllGesturesEnabled(false);
        map.getUiSettings().setZoomControlsEnabled(false);
        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        updatePlaces(this);

        return v;
    }

    private void updatePlaces(Context c)
    {
        locMan = (LocationManager)c.getSystemService(LOCATION_SERVICE);
        Location lastLoc = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

        double lat = lastLoc.getLatitude();
        double lng = lastLoc.getLongitude();

        LatLng lastLatLng = new LatLng(lat, lng);

        if (userMarker!=null) userMarker.remove();

        userMarker = map.addMarker(new MarkerOptions()
            .position(lastLatLng)
            .title("You are here")
            .icon(BitmapDescriptorFactory.fromResource(userIcon))
            .snippet("Your last recorder location"));

        map.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng), 3000, null);
        locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 30000, 50, this);
    }
替换这个

updatePlaces(this);

公众最终活动

返回此片段当前关联的活动。

替换此片段

updatePlaces(this);

公众最终活动

返回此片段当前关联的活动。

因为片段不是上下文,所以需要调用此片段关联的活动,如下所示:

updatePlaces(this.getActivity());
由于片段不是上下文,您需要调用与此片段关联的活动,如下所示:

updatePlaces(this.getActivity());