我是android新手,我需要你的帮助。我有两个输入纬度和经度的编辑文本和一个按钮搜索。我的问题是单击按钮搜索后如何在地图上显示位置?请在此处提供一些示例代码。
问问题
1684 次
2 回答
0
据我了解,您希望将 MapView 设置为用户放入 EditText 的坐标。
float latitude = new Float(lat.getText().toString()); //Check for errors here
float longitude = new Float(long.getText().toString()); //Check for errors here
//Create a GeoPoint, which takes lat/long in microdegrees:
GeoPoint point = new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6));
//Use MapController to move your mapview
MapController controller = yourMapView.getController();
controller.animateTo(point);
//Or, without the scroll animation:
//controller.setCenter(point);
您可以在此处阅读有关 MapView 和 MapController 类的更多信息: https ://developers.google.com/maps/documentation/android/reference/com/google/android/maps/MapController https://developers.google.com/maps /documentation/android/reference/com/google/android/maps/MapView
于 2012-05-12T17:14:57.327 回答
0
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
LocationManager locManager =
(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if(locManager.getBestProvider(criteria,true) != null){
Location myLocation= locManager.getLastKnownLocation(locManager.getBestProvider(criteria, true));
String latitude = Double.toString(myLocation.getLatitude());
String longitude = Double.toString(myLocation.getLongitude());
String altitude = Double.toString(myLocation.getAltitude());
}
于 2012-05-12T16:38:20.697 回答