我想在海roid的海图中显示每个5秒的纬度和长度清单。 我已尝试过此事。
:
public class MapdemoActivity extends ListActivity
{
private ArrayList<MapData> mapdata = new ArrayList<MapData>();
private MapDataAdapter m_adapter;
public String lng;
public String lat;
private Button retrieveLocationButton;
private LocationManager locationManager;
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; //1 meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 5000; //5 seconds
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
this.m_adapter = new MapDataAdapter(this, R.layout.row, mapdata);
setListAdapter(this.m_adapter);
}
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location location)
{
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null)
{
lat=Double.toString(location.getLatitude());
lng=Double.toString(location.getLongitude());
MapData data = new MapData();
data.setLatitude(lat);
data.setLongitude(lng);
mapdata.add(data);
Log.i("Lat", mapdata.get(0).Latitude);
Log.i("Lng", lng+location.getLatitude());
}
}
public void onStatusChanged(String s, int i, Bundle b) {
Toast.makeText(MapdemoActivity.this, "Provider status changed",
Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s) {
Toast.makeText(MapdemoActivity.this,
"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();
}
public void onProviderEnabled(String s) {
Toast.makeText(MapdemoActivity.this,
"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();
}
}
private class MapDataAdapter extends ArrayAdapter<MapData>
{
private ArrayList<MapData> items;
public MapDataAdapter(Context context, int textViewResourceId, ArrayList<MapData> items)
{
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
MapData o = items.get(position);
if (o != null)
{
TextView lat = (TextView) v.findViewById(R.id.tt1);
TextView lng = (TextView) v.findViewById(R.id.tt2);
if (lat != null)
{
lat.setText("Latitude: "+o.getLatitude());
}
if(lng != null)
{
lng.setText("Longitude: "+ o.getLongitude());
}
}
return v;
}
}
}
http://www.ohchr.org。
package com.ap.map.demo;
public class MapData
{
public String Longitude;
public String Latitude;
public String getLatitude() {
return Latitude;
}
public void setLatitude(String latitude) {
this.Latitude = latitude;
}
public String getLongitude() {
return Longitude;
}
public void setLongitude(String longitude) {
this.Longitude = longitude;
}
}
It does not show anything in the listview.No error.But the changes are not getting recognized. Can anyone help me on this.