当我扩展MapFragment时,这个错误带有十字标志:构造函数Geocoder(Map_Tracker,Locale)是undefined.Also我导入:import android.location.Geocoder; 我做了片段类和下面的代码我删除了一些代码:
public class Map_Tracker extends MapFragment {
MapView myMapView;
View rootView;
public Map_Tracker() { }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
rootView = inflater.inflate(R.layout.frag_tracker, container, false);
myMapView = (MapView)rootView.findViewById(R.id.mapView);
updateWithNewLocation(location);
return rootView;
}
private void updateWithNewLocation(Location location) {
// TODO Auto-generated method stub
String latLongString;
TextView myLocationText;
myLocationText = (TextView)rootView.findViewById(R.id.textView1);
String addressString = "No Address Found";
if(location != null)
{
// Update the map Location
Double geoLat = location.getLatitude()*1E6;
Double geoLng = location.getLongitude()*1E6;
GeoPoint point = new GeoPoint(geoLat.intValue(),geoLng.intValue());
mapController.animateTo(point);
Double lat = location.getLatitude();
Double lng = location.getLongitude();
Geocoder gc = new Geocoder(Map_Tracker.this, Locale.getDefault());
try
{
List<Address> addresses = gc.getFromLocation(latitude, longitude, 1);
StringBuilder sb = new StringBuilder();
}
}
}
//这一行出错:
Geocoder gc = new Geocoder(Map_Tracker.this, Locale.getDefault());
答案 0 :(得分:1)
试试这个
Geocoder gc = new Geocoder(getActivity(), Locale.getDefault());
而不是
Geocoder gc = new Geocoder(Map_Tracker.this, Locale.getDefault());
在片段
中