下面的代码应该跟踪用户的当前位置,但是“ 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);
}
取代这个
updatePlaces(this);
经过
updatePlaces(getActivity());
public final Activity getActivity ()
返回当前与Activity
此fragment
关联的对象。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句