我顯示在emaluator的谷歌地圖..的Android谷歌地圖顯示
這裏是代碼段..
在我已經使用XML加入編輯框給定的代碼段,並且在該編輯框一用戶輸入他想要搜索的位置的名稱。
問題是我無法獲取用戶輸入的名稱並搜索相應的位置。
Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
try {
go.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
result = edit.getText().toString();
}
});
List<Address> addresses = geoCoder.getFromLocationName(result, 5);
String add = "";
if (addresses.size() > 0) {
p = new GeoPoint(
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
}
} catch (IOException e) {
e.printStackTrace();
}
我已經使用地理編碼器..
這裏是XML代碼片斷..
<EditText
android:id="@+id/edit"
android:layout_width="257px"
android:layout_height="wrap_content"
android:textSize="18sp"
>
</EditText>
<Button
android:id="@+id/button"
android:layout_width="44px"
android:layout_height="33px"
android:text="GO"
>
</Button>
u能請找我的錯誤並糾正我嗎?
運行此代碼時是否引發異常?我最初的猜測是你的'edit'對象(我認爲它是一個EditText)是無效的。您可能只想在'onClick'中調用'findViewById(r.id.editTextID)'。 – 2011-03-11 02:33:08
您是否在第5行獲得結果?或者你有沒有面對pbm?請解釋... – Mathew 2011-03-11 04:05:52