1

我有一个工作应用程序和带有地址的数据库(在项目搜索应用程序中),我需要在谷歌地图上显示。当用户单击搜索时,他从数据库中获取项目详细信息和供应商的详细信息,包括地址和第二个活动中显示的所有内容。所有这些都有效,但所有产品的地图上只显示一个位置。问题是如何根据其位置在地图特定的数据库地址上显示(在我已经拥有的第三个活动上,使用工作地图显示)?

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