2012-05-12 35 views

回答

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()); 
} 
+0

,我把這個代碼? –

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

+0

謝謝,我把這個代碼放在哪裏? –

+0

如果您希望在單擊搜索按鈕時移動地圖,請將其放入搜索按鈕的OnClickListener中。 – Zambotron

相關問題