Android Programming Tutorials

(Romina) #1
Here a Post, There a Post

@Override
protected boolean isRouteDisplayed() {
return(false);
}
}

Now, if you rebuild and reinstall Patchy (and PostMonitor!), and you click on


a status that has a location (L:nnn.nn,nnn.nn – you may need somebody to


update their status with a location for you!), it will open the map on that


location.


Step #4: Show the Location Via a Pin


Finally, it would be good to put a pin on the map at the spot identified by


the status. Not only will this help the user find the location again after


panning around the map, but we can also have the pin respond to a click by


displaying the text of the status update.


First, find yourself a suitable pin image, probably on the order of 32x32


pixels. In this code, we assume that the pin image is called marker.


Next, add the following lines to onCreate() in StatusMap:


String statusText=getIntent().getStringExtra(Patchy.STATUS_TEXT);
Drawable marker=getResources().getDrawable(R.drawable.marker);

marker.setBounds( 0 , 0 , marker.getIntrinsicWidth(),
marker.getIntrinsicHeight());

map.getOverlays().add(new StatusOverlay(marker, status,
statusText));

This requires an implementation of StatusOverlay – add the following inner


class to StatusMap:


private class StatusOverlay extends ItemizedOverlay<OverlayItem> {
private OverlayItem item=null;
private Drawable marker=null;

public StatusOverlay(Drawable marker, GeoPoint status,
String statusText) {

240
Free download pdf