android google maps需要从sqlite添加标记帮助
我正在尝试从SQLite数据库在谷歌地图上添加广告标记 我有一个列表视图,可以从数据库中看到纬度和经度。所以我知道db正在工作。 我是java和android新手。但我希望情况会好转。 我不确定我的代码是否正确,需要一些帮助。。 这是我写的代码: List mapOverlays=mapView.getOverlays() 上面的代码显示了其工作引脚的当前位置:-) 下面的代码我不知道如何去上班android google maps需要从sqlite添加标记帮助,android,sqlite,google-maps,google-maps-markers,Android,Sqlite,Google Maps,Google Maps Markers,我正在尝试从SQLite数据库在谷歌地图上添加广告标记 我有一个列表视图,可以从数据库中看到纬度和经度。所以我知道db正在工作。 我是java和android新手。但我希望情况会好转。 我不确定我的代码是否正确,需要一些帮助。。 这是我写的代码: List mapOverlays=mapView.getOverlays() 上面的代码显示了其工作引脚的当前位置:-) 下面的代码我不知道如何去上班 public ArrayList<OverlayItem> getLocatio
public ArrayList<OverlayItem> getLocations()
{
ArrayList<OverlayItem> locations = new ArrayList<OverlayItem>();
String[] tableColumns = new String[]{"_id", "address", "description", "latitude", "longitude"};
Cursor cursor = db.query("spots", tableColumns, null, null, null, null, null);
cursor.moveToFirst();
do{
String adress = (cursor.getString(cursor.getColumnIndex("adress")));
String description = (cursor.getString(cursor.getColumnIndex("description")));
String lat1 = (cursor.getString(cursor.getColumnIndex("latitude")));
Double lat = Double.parseDouble(lat1);
String long1 = (cursor.getString(cursor.getColumnIndex("longitude")));
Double lon = Double.parseDouble(long1);
GeoPoint point = new GeoPoint((int) (lat * 1E6),(int) (lon * 1E6));
locations.add(new OverlayItem(point, adress, description));
}
while (cursor.moveToNext());
return locations;
}
// missing some code here to ad to my CurrentLocationOverlay class ore do i have to make a
//new class for this ??
public ArrayList getLocations()
{
ArrayList位置=新的ArrayList();
String[]tableColumns=新字符串[]{“\u id”,“地址”,“描述”,“纬度”,“经度”};
Cursor Cursor=db.query(“点”,tableColumns,null,null,null,null);
cursor.moveToFirst();
做{
字符串地址=(cursor.getString(cursor.getColumnIndex(“地址”));
字符串描述=(cursor.getString(cursor.getColumnIndex(“描述”));
字符串lat1=(cursor.getString(cursor.getColumnIndex(“纬度”));
Double lat=Double.parseDouble(lat1);
字符串long1=(cursor.getString(cursor.getColumnIndex(“经度”));
Double lon=Double.parseDouble(long1);
地质点=新的地质点((int)(纬度*1E6),(int)(纬度*1E6));
添加(新的覆盖项(点、地址、说明));
}
while(cursor.moveToNext());
返回地点;
}
//这里缺少一些代码来添加到我的CurrentLocationOverlay类中,或者我必须创建一个
//这个新班级??
这是CurrentLocationOverlay.class
public class CurrentLocationOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
public CurrentLocationOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
public void addOverlay(OverlayItem item){
mOverlays.add(item);
setLastFocusedIndex(-1);
populate(); // Calls the method createItem()
}
@Override
protected boolean onTap(int arg0) {
Log.d("Tapped", mOverlays.get(arg0).getSnippet());
return true;
}
}
公共类CurrentLocationOverlay扩展了ItemizeOverlay{
private ArrayList mOverlays=new ArrayList();
公共CurrentLocationOverlay(可绘制的默认标记){
super(boundCenterBottom(defaultMarker));
}
@凌驾
受保护的OverlayItem createItem(int i){
返回mOverlays.get(i);
}
@凌驾
公共整数大小(){
返回mOverlays.size();
}
公共void addOverlay(OverlayItem项){
添加(项目);
setLastFocusedIndex(-1);
populate();//调用createItem()方法
}
@凌驾
受保护的布尔onTap(int arg0){
Log.d(“Tapped”,mOverlays.get(arg0.getSnippet());
返回true;
}
}
这里是如何使用SQLite的示例:
公共类DBHelper扩展了SQLiteOpenHelper{
public static interface POSITION extends BaseColumns {
String TABLE_NAME = "position";
String LATITUDE = "latitude";
String LONGTITUDE = "longtitude";
}
以及如何获得所需的坐标:
public class HelloGoogleMap extends MapActivity {
private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS ";
private static final String CREATE_TABLE_POSITION = CREATE_TABLE + POSITION.TABLE_NAME + " ("
+ POSITION._ID + " INTEGER PRIMARY KEY, " + POSITION.LATITUDE + " INTEGER, "
+ POSITION.LONGTITUDE + " INTEGER);";
private static final String DATABASE_NAME = "Pointer";
private static final int DATABASE_VERSION = 3;
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_POSITION);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + POSITION.TABLE_NAME);
onCreate(db);
}
public void insertPosition(long latitde, long longtitude) {
ContentValues values = new ContentValues();
values.put(POSITION.LATITUDE, latitde);
values.put(POSITION.LONGTITUDE, longtitude);
getWritableDatabase().insert(POSITION.TABLE_NAME, null, values);
}
public Cursor getAllPoints() {
return getReadableDatabase().query(POSITION.TABLE_NAME,
new String[] { POSITION.LATITUDE, POSITION.LONGTITUDE }, null, null, null, null, null);
}
}
public class HelloGoogleMap extends MapActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable herUAre = this.getResources().getDrawable(R.drawable.ic_launcher);
CurrentLocationOverlay currentLocationOverlay = new CurrentLocationOverlay(herUAre);
OverlayItem[] currentLocation = new OverlayItem[10];
DBHelper db = new DBHelper(this);
db.insertPosition(50030936, 3622452);
db.insertPosition(52033986, 3623859);
db.insertPosition(56034932, 3625129);
db.insertPosition(58039959, 3627329);
Cursor allPoints = db.getAllPoints();
int a = 0;
while (allPoints.moveToNext()) {
Log.e("" + allPoints.getLong(allPoints.getColumnIndex(DBHelper.POSITION.LATITUDE)), ""
+ allPoints.getLong(allPoints.getColumnIndex(DBHelper.POSITION.LONGTITUDE)));
currentLocation[a] = new OverlayItem(new GeoPoint((int) allPoints.getLong(allPoints
.getColumnIndex(DBHelper.POSITION.LATITUDE)), (int) allPoints.getLong(allPoints
.getColumnIndex(DBHelper.POSITION.LONGTITUDE))), "Current Location", null);
currentLocationOverlay.addOverlay(currentLocation[a]);
a++;
}
allPoints.close();
db.close();
mapOverlays.clear();
mapOverlays.add(currentLocationOverlay);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}