无法实例化GeoPoint Android类型

时间:2013-12-24 04:34:24

标签: android google-maps

我正在尝试建立一个简单的应用程序,当用户输入他想要的位置时,它的地图会出现。但是我收到错误无法实例化GeoPoint类型我还安装了Google Play服务。 这是代码:

 public class MainActivity extends MapActivity {

EditText location;
Geocoder geoCoder;
GeoPoint p;
MapController controller;
MapView mapView;
Button btnSearch;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    location=(EditText)findViewById(R.id.txtAddress);
     mapView = (MapView) findViewById(R.id.mapView);
    btnSearch.setOnClickListener(new View.OnClickListener() {                             

        public void onClick(View arg0) {


    List<Address> addresses;
    try {
        addresses = geoCoder.getFromLocationName(location.getText().toString(),1);
        if(addresses.size() > 0)
        {
             p = new GeoPoint( (int) (addresses.get(0).getLatitude() * 1E6), 
                              (int) (addresses.get(0).getLongitude() * 1E6));

               controller.animateTo(p);
               controller.setZoom(12);

               MapOverlay mapOverlay = new MapOverlay();
             List<Overlay> listOfOverlays = mapView.getOverlays(); 
                     listOfOverlays.clear();
             listOfOverlays.add(mapOverlay);

               mapView.invalidate();
               location.setText("");
        }
        else
        {
                AlertDialog.Builder adb = new AlertDialog.Builder(MainActivity.this);
                adb.setTitle("Google Map");
                adb.setMessage("Please Provide the Proper Place");
                adb.setPositiveButton("Close",null);
                adb.show();
        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
        }
        });



}

1 个答案:

答案 0 :(得分:0)

是否有特殊原因需要使用Google maps api的v1而不是当前的v2?如果没有,请尝试使用LatLng存储位置,并使用map.moveCamera(LatLng,float zoom)转到所需的位置here