我想在使用虚拟设备(模拟器 Android)时在地图上找到位置,因为我没有实际设备。感谢收看!
这是我的代码:
enter code herepublic class GoogleMapExample3Activity extends MapActivity {
/** Called when the activity is first created. */
MapView mapView;
TextView txtView;
LinearLayout zoomControl;
GeoPoint geoPoint;
MapController mapController;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView=(MapView) findViewById(R.id.mapView);
zoomControl=(LinearLayout) findViewById(R.id.zoomControl);
View view= mapView.getZoomControls();
zoomControl.addView(view,new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
mapView.setSatellite(true);
String address="New York";
Geocoder geoCoder=new Geocoder(this);
List<Address> list;
try {
list = geoCoder.getFromLocationName(address, 1);
Address a=list.get(0);
Double latitude=a.getLatitude();
Double longitude=a.getLongitude();
geoPoint=new GeoPoint( (int)(latitude*1E6),(int)(longitude*1E6));
mapController=mapView.getController();
mapController.animateTo(geoPoint);
mapController.setZoom(18);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
MapController mapController=mapView.getController();
switch (keyCode) {
case KeyEvent.KEYCODE_I:
mapController.zoomIn();
break;
case KeyEvent.KEYCODE_O:
mapController.zoomOut();
break;
default:
break;
}
return super.onKeyDown(keyCode, event);
}
}
我尝试了但无法从用户输入的地址中获取位置!我需要你帮忙!