GoogleMaps на Android, используя Google API 2.3.3 Уровень 10, поиск по адресу - PullRequest
1 голос
/ 15 декабря 2011

Я пытаюсь отобразить адрес из EditText, используя geoCoder, а также он может редактировать, нажав на кнопку поиска и обновить отображение Googlemap в верхней части экрана, это мой код:

Geocoder geocoder = null;
MapView mapView = null;
int lat, lng;
EditText loc;

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

@Override
protected void onCreate(Bundle icicle) {

    super.onCreate(icicle);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.geoMap);

    try 
    {
        loc = (EditText)findViewById(R.id.location);
        String locationName = loc.getText().toString();
        List<Address> addressList = geocoder.getFromLocationName(locationName, 5);

        if (addressList != null && addressList.size() > 0) {
            lat = (int) addressList.get(0).getLatitude() * 1000000;
            lng = (int) addressList.get(0).getLongitude() * 1000000;
            GeoPoint pt = new GeoPoint(lat, lng);
            mapView.getController().setZoom(10);
            mapView.getController().setCenter(pt);
            mapView.getController().animateTo(pt);
        }
    } 
    catch 
    (IOException e) 
    {
        e.printStackTrace();
    }



    //
    Button geoBtn = (Button) findViewById(R.id.geocodeBtn);
    geocoder = new Geocoder(this);
    //
    geoBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            try {
                EditText loc = (EditText) findViewById(R.id.location);
                String locationName = loc.getText().toString();
                List<Address> addressList = geocoder.getFromLocationName(locationName, 5);

                if (addressList != null && addressList.size() > 0) {
                    int lat = (int) addressList.get(0).getLatitude() * 1000000;
                    int lng = (int) addressList.get(0).getLongitude() * 1000000;
                    GeoPoint pt = new GeoPoint(lat, lng);
                    mapView.getController().setZoom(10);
                    mapView.getController().setCenter(pt);
                    mapView.getController().animateTo(pt);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}

Но в этот момент происходит сбой: List addressList = geocoder.getFromLocationName (locationName, 5); Я использую Google APi 2.3.3.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...