1

EditTextで地図の検索場所を指定してから、地図にその場所を表示しています。必要なのはこれです。地図の場所をクリックしたときにダイアログを表示したいですか?その場所をAndroidに移動できるようにしますListView

package com.example.tutorials;

import java.io.IOException;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Geocoder;
import android.location.LocationManager;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import com.google.android.maps.MapView.LayoutParams;  
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;


public class GoogleMap extends MapActivity  
{

     MapView mapView; 

    /** Called when the activity is first created. */
    @Override
    protected boolean isRouteDisplayed() 
    {
    return false;
    }

    public void changeMap(String area)
    {

    mapView = (MapView) findViewById(R.id.mapview);
    MapController mc=mapView.getController();


    GeoPoint myLocation=null;

    double lat = 0;
    double lng = 0;
    try
    {

    Geocoder g = new Geocoder(this, Locale.getDefault());

    java.util.List<android.location.Address> result=g.getFromLocationName(area, 1);
    if(result.size()>0){

    Toast.makeText(GoogleMap.this, "country: " + String.valueOf(result.get(0).getCountryName()), Toast.LENGTH_SHORT).show();
    lat = result.get(0).getLatitude();
    lng = result.get(0).getLongitude();

    }            
    else{
    Toast.makeText(GoogleMap.this, "record not found", Toast.LENGTH_SHORT).show();
    return;
    }
    }
    catch(IOException io)
    {
    Toast.makeText(GoogleMap.this, "Connection Error", Toast.LENGTH_SHORT).show();
    }
    myLocation = new GeoPoint(
    (int) (lat * 1E6),
    (int) (lng * 1E6));
    Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
    mc.animateTo(myLocation);
    mc.setZoom(10);
    mapView.invalidate();
    }
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btnSearch=(Button) findViewById(R.id.btnSearch);
        btnSearch.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {


        EditText txtSearch=(EditText)findViewById(R.id.txtMapSearch);
        String area=txtSearch.getText().toString();
        Toast.makeText(GoogleMap.this, "Click-" + String.valueOf(area), Toast.LENGTH_SHORT).show();
        GoogleMap.this.changeMap(area);


                    }
        });

        mapView = (MapView) findViewById(R.id.mapview);
        MapController mapController = mapView.getController();
        mapController.setZoom(14);

        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom); 

        }

    }

一度見て、上記のコードをどこで変更できるか教えてください。

4

1 に答える 1

1

ダイアログボックスを表示するには、次のコードに従います。

public class MapViewer extends MapActivity {

MapView mapView;

MapController mapController;

GeoPoint mgeoPoint;

Drawable marker;

MyLocationOverlay mLocationOverlay;

MotionEvent e;


@Override
protected void onCreate(Bundle icicle) {

// TODO Auto-generated method stub
super.onCreate(icicle);
setContentView(R.layout.main);

mapView = (MapView) findViewById(R.id.mapView);

mapController = mapView.getController();

mapView.setBuiltInZoomControls(true);

mapView.setStreetView(true);


marker = getResources().getDrawable(R.drawable.pushpin);

marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker
        .getIntrinsicHeight());

mapView.getOverlays().add(new MapOverlay(marker));


mLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(mLocationOverlay);

setViewLocation();
}


@Override
protected Dialog onCreateDialog(int id) {

// TODO Auto-generated method stub

switch (id) {
    case 0:
        return new AlertDialog.Builder(this).setTitle("Hello").setIcon(
                R.drawable.ic_launcher).setPositiveButton("Yes",
                new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog , int which) {

                        // TODO Auto-generated method stub

                    }
                }).setCancelable(true).setNegativeButton("Cancel",
                new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog , int which) {

                        // TODO Auto-generated method stub

                    }
                })

        .setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {

                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "Dismiss",
                        Toast.LENGTH_SHORT).show();
            }

        }).create();


    default:
        break;
}
return null;
    }


private void setViewLocation() {



String[] coordinates = { "22.716221", "75.896816" };

double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
mgeoPoint = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));

mapController.animateTo(mgeoPoint);
mapController.setZoom(15);

mapView.invalidate();

}


@Override
protected boolean isRouteDisplayed() {

// TODO Auto-generated method stub
return false;
}


Point scrPoint;


private GeoPoint getPoint(double lat , double lon) {

return (new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6)));
}


class MapOverlay extends
    com.google.android.maps.ItemizedOverlay<OverlayItem> {

List<OverlayItem> ListofGeopoints = new ArrayList<OverlayItem>();


public MapOverlay(Drawable defaultMarker ) {

    super(defaultMarker);

    ListofGeopoints.add(new OverlayItem(getPoint(22.716221, 75.896816),
            "IN", "India"));

    populate();

}


@Override
protected boolean onTap(int index) {

switch (index) {
        case 0:
            Toast.makeText(getApplicationContext(), "GeoLocation : 0",
                    Toast.LENGTH_LONG).show();
            showDialog(0);
        break;
    }

    return true;
}


String add = "";

List<Address> add_List = new ArrayList<Address>();


private void getAddress() {

    add_List = ReverseGeocode
            .getFromLocation(35.594227, -105.223618, 2);

}


@Override
protected OverlayItem createItem(int i) {
    return (ListofGeopoints.get(i));
}


@Override
public int size() {
    return ListofGeopoints.size();
}
}  
}
于 2012-05-03T09:41:54.827 に答える