1

動作中のアプリとアドレス付きのデータベース(アイテム検索アプリ内)があり、Googleマップに表示する必要があります。ユーザーが[検索]をクリックすると、dbからアイテムの詳細とベンダーの詳細が取得されます。これには、アドレスと2番目のアクティビティに表示されるすべてのものが含まれます。すべてが機能しますが、すべての製品について1つの場所のみがマップに表示されます。質問は、その場所に応じて、マップ固有のDBアドレスに(マップ表示が機能している、私がすでに持っている3番目のアクティビティで)表示する方法です。

DetaljiProizvoda.java(アイテムの詳細)

public class DetaljiProizvoda extends Activity {

protected TextView naziv;
protected TextView kategorija;
protected TextView tvrtka;
protected TextView telefonTvrtke;
protected TextView adresaTvrtke;
protected int proizvodId;
protected Cursor cursor; //dodatak na finalni activity prikaza lokacije proizvoda
protected ListAdapter adapter; //dodatak na finalni activity prikaza lokacije proizvoda


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.detalji_proizvoda);
    //hvatanje parametra (ID iz tablice) Intenta iz ListaProizvoda activity-a
    proizvodId = getIntent().getIntExtra("PROIZVODI_ID", 0);
    SQLiteDatabase db = (new DatabaseHelper(this)).getWritableDatabase();
    Cursor cursor = db.rawQuery("SELECT proizv._id, proizv.naziv, proizv.tvrtka, proizv.cijena, proizv.kategorija, proizv.telefonTvrtke, proizv.adresaTvrtke FROM proizvodi proizv LEFT OUTER JOIN proizvodi mgr ON proizv._id = mgr._id WHERE proizv._id = ?", 
            new String[]{""+proizvodId});

    if (cursor.getCount() == 1)
    {
        cursor.moveToFirst();

        naziv = (TextView) findViewById(R.id.naziv);
        naziv.setText(cursor.getString(cursor.getColumnIndex("naziv"))); /*+ " " + cursor.getString(cursor.getColumnIndex("lastName")));*/

        kategorija = (TextView) findViewById(R.id.kategorija);
        kategorija.setText(cursor.getString(cursor.getColumnIndex("kategorija")));

        tvrtka = (TextView) findViewById(R.id.tvrtka);
        tvrtka.setText(cursor.getString(cursor.getColumnIndex("tvrtka")));

        telefonTvrtke = (TextView) findViewById(R.id.telefonTvrtke);
        telefonTvrtke.setText(cursor.getString(cursor.getColumnIndex("telefonTvrtke")));

        adresaTvrtke = (TextView) findViewById(R.id.adresaTvrtke);
        adresaTvrtke.setText(cursor.getString(cursor.getColumnIndex("adresaTvrtke")));

    }
    //zatvaranje baze
    cursor.close();
    db.close(); 

}

  //default button handler
    public void changeActivity(View view) { 
        startActivity(new Intent(this, GMapsActivity.class));
    }                    

} 

GMapsActivity.java

public class GMapsActivity extends MapActivity {

    private MapView mapView;
    private static final int latitudeE6 = 37985339;
    private static final int longitudeE6 = 23716735;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.gmaps_layout);

        mapView = (MapView) findViewById(R.id.map_view);       
        mapView.setBuiltInZoomControls(true);

        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
        CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);

        GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
        OverlayItem overlayitem = new OverlayItem(point, "Hello", "I'm in Athens, Greece!");

        itemizedOverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedOverlay);

        MapController mapController = mapView.getController();

        mapController.animateTo(point);
        mapController.setZoom(6);

    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

}

gmaps_layout.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map_view"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:clickable="true" 
        android:enabled="true" 
        android:apiKey="0vwcQJvEOXRQcyAhZxPToaeuss2Lhodp_qGYkTA" />

</RelativeLayout>

DetaljiProizvoda.java

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="12dp"
    android:paddingLeft="12dp">

    <TextView
        android:id="@+id/naziv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/kategorija"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/tvrtka"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/telefonTvrtke"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/adresaTvrtke"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <Button 
        android:id="@+id/btnButton"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_gravity="left"
        android:onClick="changeActivity"
        android:text="@string/prikazi_lokaciju"
        android:textSize="12dp" />

</LinearLayout>

CustomItemizedOverlay.javaファイルも

4

0 に答える 0