Я создаю приложение.В котором сейчас я получаю карту, а также широту и долготу места, к которому прикоснулись.Я также хотел адрес точки касания, соответствующей широте и долготе.Как я могу добиться этого?
public class MapViewEvents extends MapActivity {
private TextView myLongitude, myLatitude;
String result1;
private Context context;
private MapView myMapView;
private MapController myMapController;
private double la;
private double lo;
@Override
protected void onCreate(Bundle icicle) {
// TODO Auto-generated method stub
super.onCreate(icicle);
setContentView(R.layout.mymapview);
myMapView = (MapView)findViewById(R.id.mapview);
myMapController = myMapView.getController();
myMapView.setBuiltInZoomControls(true);
myLongitude = (TextView)findViewById(R.id.longitude);
myLatitude = (TextView)findViewById(R.id.latitude);
la= RoamMeo_Config.Gpslatitude;
lo=RoamMeo_Config.Gpslongitude;
int latitude = (int)(la * 1000000);
int longitude = (int)(lo * 1000000);
GeoPoint initGeoPoint = new GeoPoint(latitude, longitude);
CenterLocation(initGeoPoint);
Button nxt_button = (Button) findViewById(R.id.btn_next);
nxt_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//System.out.println(result1);
//Intent intent = new Intent(Home.this, EventList.class);
//startActivity(intent);
}
});
}
private void placeMarker(int markerLatitude, int markerLongitude)
{
Drawable marker=getResources().getDrawable(
android.R.drawable.ic_menu_myplaces);
marker.setBounds(0, 0, marker.getIntrinsicWidth(),
marker.getIntrinsicHeight());
myMapView.getOverlays().add(new InterestingLocations(marker,
markerLatitude, markerLongitude));
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
private void CenterLocation(GeoPoint centerGeoPoint)
{
myMapController.animateTo(centerGeoPoint);
myLongitude.setText("Longitude: "+
String.valueOf((float)centerGeoPoint.getLongitudeE6()/1000000));
myLatitude.setText("Latitude: "+
String.valueOf((float)centerGeoPoint.getLatitudeE6()/1000000));
placeMarker(centerGeoPoint.getLatitudeE6(),
centerGeoPoint.getLongitudeE6());
};
class InterestingLocations extends ItemizedOverlay<OverlayItem>{
private List<OverlayItem> locations =
new ArrayList<OverlayItem>();
private Drawable marker;
private OverlayItem myOverlayItem;
boolean MoveMap;
public InterestingLocations(Drawable defaultMarker,
int LatitudeE6, int LongitudeE6) {
super(defaultMarker);
// TODO Auto-generated constructor stub
this.marker=defaultMarker;
// create locations of interest
GeoPoint myPlace = new GeoPoint(LatitudeE6,LongitudeE6);
myOverlayItem = new OverlayItem(myPlace, "My Place", "My Place");
locations.add(myOverlayItem);
populate();
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return locations.get(i);
}
@Override
public int size() {
// TODO Auto-generated method stub
return locations.size();
}
@Override
public void draw(Canvas canvas, MapView mapView,
boolean shadow) {
// TODO Auto-generated method stub
super.draw(canvas, mapView, shadow);
boundCenterBottom(marker);
}
@Override
public boolean onTouchEvent(MotionEvent arg0, MapView arg1) {
// TODO Auto-generated method stub
//super.onTouchEvent(arg0, arg1);
int Action = arg0.getAction();
if (Action == MotionEvent.ACTION_UP){
if(!MoveMap)
{
Projection proj = myMapView.getProjection();
GeoPoint loc = proj.fromPixels((int)arg0.getX(), (int)arg0.getY());
//remove the last marker
myMapView.getOverlays().remove(0);
CenterLocation(loc);
}
}
else if (Action == MotionEvent.ACTION_DOWN){
MoveMap = false;
}
else if (Action == MotionEvent.ACTION_MOVE){
MoveMap = true;
}
return super.onTouchEvent(arg0, arg1);
//return false;
}
Я выполнил приведенный ниже код, и я получил эту ошибку, напечатанную в моем
logcat:
11-09 15:00:46.318: W/System.err(664): java.io.IOException: Service not Available
11-09 15:00:46.469: W/System.err(664): at android.location.Geocoder.getFromLocation(Geocoder.java:117)
11-09 15:00:46.469: W/System.err(664): at com.project.r
oammeo.MapViewEvents$1.onClick(MapViewEvents.java:79)
11-09 15:00:46.469: W/System.err(664): at android.view.View.performClick(View.java:2408)
11-09 15:00:46.469: W/System.err(664): at android.view.View$PerformClick.run(View.java:8816)
11-09 15:00:46.478: W/System.err(664): at android.os.Handler.handleCallback(Handler.java:587)
11-09 15:00:46.488: W/System.err(664): at android.os.Handler.dispatchMessage(Handler.java:92)
11-09 15:00:46.498: W/System.err(664): at android.os.Looper.loop(Looper.java:123)
11-09 15:00:46.524: W/System.err(664): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-09 15:00:46.589: W/System.err(664): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 15:00:46.641: W/System.err(664): at java.lang.reflect.Method.invoke(Method.java:521)
11-09 15:00:46.641: W/System.err(664): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-09 15:00:46.660: W/System.err(664): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-09 15:00:46.660: W/System.err(664): at dalvik.system.NativeStart.main(Native Method)