I guess you have all tried "Google Places" in Maps. This is a list of POI close to you.
I really would like to do the same feature in my application with a list of GPS coordinates, but that seem really complicated.
Making the listview with the distance and the little arrow is very easy, but I cannot understand how to update this list and the arrow everytime the user move his phone.
For now I have a static listview.
I would like to know if someone succeed to create such a listview.
Thank a lot for any information.
There are a few options for what you're trying to achieve. Personally, I'd recommend implementing your own Adapter (most likely in this case by extending SimpleCursorAdapter) and encapsulating the updates to distance text and compass heading rotation within that.
To help with resource management, you probably want to create a SensorListener and LocationListener within the Activity that will host the ListView. Whenever you receive an update call your self-rolled updateCompassAndLocation
method from within your Adapter class.
From within that method you have two options. Either iterate over each of the items that make up the data collection being represented and modify the compass graphic and distance text, or simply record the current location and heading as variables within the class, and call notifyDataSetChanged
to force the adapter to update the views itself within the getView
method. In either case (especially the latter), you'll need to set the distance text and heading compass values within getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout myView;
MyPOI item = getItem(position);
Location poiLocation = item.getLocation;
int compassHeading = // Calculate heading relative to current heading
float distance = // Calculate distance to POI
if (convertView == null) {
myView = new LinearLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(inflater);
vi.inflate(resource, myView, true);
} else {
trainView = (LinearLayout) convertView;
}
TextView distanceView = (TextView)trainView.findViewById(R.id.distance);
ImageView compassView = (ImageView)trainView.findViewById(R.id.compass);
distanceView.setText(String.valueOf(distance);
compassView.setImageLevel(compassHeading);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With