Android 基于数据库中的地址显示地图位置
我有一个正在工作的应用程序和数据库,其中包含我需要在谷歌地图上显示的项目搜索应用程序中的地址。当用户单击“搜索”时,他从数据库中获取项目详细信息和供应商详细信息,包括地址和第二个活动中显示的所有信息。所有这些都有效,但地图上只显示了所有产品的一个位置。问题是如何在我已经拥有的第三个活动上显示,工作地图显示在地图特定的DB地址上,具体取决于它的位置 DetaljiProizvoda.java项目的详细信息Android 基于数据库中的地址显示地图位置,android,database,google-maps,Android,Database,Google Maps,我有一个正在工作的应用程序和数据库,其中包含我需要在谷歌地图上显示的项目搜索应用程序中的地址。当用户单击“搜索”时,他从数据库中获取项目详细信息和供应商详细信息,包括地址和第二个活动中显示的所有信息。所有这些都有效,但地图上只显示了所有产品的一个位置。问题是如何在我已经拥有的第三个活动上显示,工作地图显示在地图特定的DB地址上,具体取决于它的位置 DetaljiProizvoda.java项目的详细信息 public class DetaljiProizvoda extends Activity
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));
}
}
gmapactivity.java
gmaps_layout.xml
DetaljiProizvoda.java
还有CustomItemizedOverlay.java文件如果我是对的,您想将参数传递给您的GMap活动吗?是的,更准确地说,是数据库中的每个地址,并且基于该地址,我应该显示其相关映射。我在detalji_proizvoda.xml上创建了“显示地图位置”按钮,该按钮非常有效,但仅适用于地图上的单个位置
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;
}
}
<?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>
<?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>