[問題] 地址反查的程式異常
請問各位先進,小弟的程式碼如下
小弟想做一個輸入地址可返回經緯度然後顯示在Google Map的小程式,
但是當我將地址輸入後按下確認卻一直發生程式異常,
看了執行的Log卻沒看到明顯的錯誤訊息,所以請大家幫忙來找茬!
先謝謝大家.
public class MyLocation extends MapActivity {
private MapView mapView;
private Geocoder geoCoder;
private GeoPoint geoPoint;
private EditText addressEdit;
private Button resetBut, submitBut;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_location);
addressEdit = (EditText) findViewById(R.id.addressEdit);
mapView = (MapView) findViewById(R.id.mapView);
mapView.getController();
mapView.setSatellite(true);
mapView.setStreetView(true);
submitBut = (Button) findViewById(R.id.submitBut);
submitBut.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (addressEdit.getText().toString() != "") {
refreshMapViewByGeoPoint(getGeoByAddress(
addressEdit.getText().toString()), mapView, 17, true);
}
}
});
resetBut = (Button) findViewById(R.id.resetBut);
resetBut.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
addressEdit.setText("");
}
});
}
public static void refreshMapViewByGeoPoint(GeoPoint geopoint, MapView mapview, int zoom, boolean bIfSatelite) {
mapview.displayZoomControls(true);
MapController mc = mapview.getController();
mc.animateTo(geopoint);
mc.setZoom(zoom);
if (bIfSatelite) {
mapview.setSatellite(true);
mapview.setStreetView(true);
} else {
mapview.setSatellite(true);
}
}
private GeoPoint getGeoByAddress(String strSearchAddress) {
geoPoint = null;
try {
if(strSearchAddress != "") {
geoCoder = new Geocoder(MyLocation.this, Locale.getDefault());
List<Address> address = geoCoder.getFromLocationName(strSearchAddress, 5);
if (!address.isEmpty()) {
geoPoint = new GeoPoint((int)(address.get(0).getLatitude() * 1E6), (int)(address.get(0).getLongitude() * 1E6));
} else {
Log.d("TAG", "Address GeoPoint NOT found.");
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return geoPoint;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_my_location, menu);
return true;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
--
『當你可以勇敢面對自己,就算失敗之神再遇到你,也會怕你。
2006大聯盟勝投王---王建民---』
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 58.114.196.184
→
08/03 17:58, , 1F
08/03 17:58, 1F