I am scrounging through some tutorials and am needing to reverse geocode addresses, but I can't get the examples working. The map displays, but it does not zoom to my geocoded location. Here is my code...
public class MapsActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapshow);
mapView = (MapView) findViewById(R.id.mapView);
mc = mapView.getController();
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocationName(
"empire state building", 15);
String add = "";
if (addresses.size() > 0) {
p = new GeoPoint(
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
mc.animateTo(p);
mapView.invalidate();
}
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}