下面的代碼應該追蹤用戶的當前位置,但是「updatePlaces(this);」給我錯誤「MainActivity.CustomMapFragment類型的方法updatePlaces(Context)不適用於參數(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);
}
非常感謝!它現在的作品:) – Berry
@BerryHermans歡迎您 – Raghunandan