2

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;
    }
}
JJD
  • 50,076
  • 60
  • 203
  • 339
savagenoob
  • 415
  • 9
  • 25
  • I just tried an actual address, set the zoom to 16, still no action. Just the default map of the US. No errors. – savagenoob Dec 14 '11 at 05:32
  • 1
    Actually I am getting a logcat error that says: "Couldn't get connection factory client" but I thought this just happened in every emulator. Maybe I'm wrong. I have the right key or a map wouldn't be displayed. – savagenoob Dec 14 '11 at 06:01
  • 1
    Jackpot..now..see this http://stackoverflow.com/questions/2199403/couldnt-get-connection-factory-client .. If you have Device..try your code on it..and I am sure It will run ok. – MKJParekh Dec 14 '11 at 06:24
  • Freakin crap, I've been messing with this thing all day to find out it was the emulator? Changed to 3.0 google api and it worked.... – savagenoob Dec 14 '11 at 06:44
  • Post it as an answer and Ill mark it as so. :) – savagenoob Dec 14 '11 at 06:46

1 Answers1

1

First Check

Does it give you any error log?..Have you tried with another addresses?,Try writting city name ...Are you trying this in emulator..then test in device cause Geocoder class don't work in emulator..if api level is 2.2..try changing it to lower and higher..may be because of zoom level you can't recognize the result..set it to mc.setZoom(16);

Then Check

I suspect the problem is within to see the result..write some Address outside the US and see if there is any difference.

Finally

If you have Device..try your code on it..and I am sure It will run ok or Use higher version Emulator.

MKJParekh
  • 34,073
  • 11
  • 87
  • 98