0
안드로이드 모바일에서지도를 볼 수있게되었습니다. 이제 검색 영역에 대해 하나의 편집 텍스트를 넣습니다. 그리고 장소를 검색하기위한 하나의 버튼을 만듭니다.안드로이드에서지도 오류의 영역을 검색하는 동안 응용 프로그램이 예기치 않게 중지되었습니다
enter code here
public class MapActivity extends com.google.android.maps.MapActivity implements
OnClickListener {
/** Called when the activity is first created. */
MapView view;
Button search;
EditText location;
MapController controller;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
view = (MapView) findViewById(R.id.themap);
location = (EditText) findViewById(R.id.editText1);
search = (Button) findViewById(R.id.search);
search.setOnClickListener(this);
view.setBuiltInZoomControls(true);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == search) {
Geocoder geo = new Geocoder(getApplicationContext(),
Locale.getDefault());
try {
List<Address> addresses = geo.getFromLocationName(location
.getText().toString(), 5);
if (addresses.size() > 0) {
GeoPoint p = new GeoPoint((int) (addresses.get(0)
.getLatitude() * 1E6), (int) (addresses.get(0)
.getLongitude() * 1E6));
controller.animateTo(p);
controller.setZoom(12);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> lisOverlays = view.getOverlays();
lisOverlays.clear();
lisOverlays.add(mapOverlay);
} else {
AlertDialog.Builder adb = new AlertDialog.Builder(
MapActivity.this);
adb.setTitle("Google Map");
adb.setMessage("please provide proper place");
adb.setPositiveButton("Close", null);
adb.show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Mapoverlay.java
public class MapOverlay extends com.google.android.maps.Overlay {
Context context;
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
super.draw(canvas, mapView, shadow);
Point screenPts = new Point();
GeoPoint p = null;
mapView.getProjection().toPixels(p, screenPts);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
R.drawable.ic_launcher);
canvas.drawBitmap(bitmap, screenPts.x, screenPts.y, null);
return true;
}
}
내 로그 고양이는 controller.animateTo (p)에 오류를 표시합니다.
위의 줄에서 오류를 어떻게 해결할 수 있습니까? 지도에서 검색 옵션을 어떻게 제공합니까? 누군가 위의 코드에서 실수가 어디 있는지 말할 수 있습니까?
나에게 도움이 될만한 정보를 입력하십시오. – Vinoth