我有一个工作的应用程序和带有地址的数据库(在项目搜索应用程序中)我需要在谷歌地图上显示。当用户单击搜索时,他从db获取项目详细信息和供应商的详细信息,包括地址和第二个活动中显示的所有内容。一切正常,但所有产品的地图上只显示一个位置。 问题是如何在地图特定的DB地址上显示(在我已有的第三个活动上,有工作地图显示),具体取决于它的位置?
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 文件