gpt4 book ai didi

Android在谷歌地图上延迟添加地理点

转载 作者:行者123 更新时间:2023-11-29 00:39:50 26 4
gpt4 key购买 nike

我想做的是在 google mapView 上添加 GeoPoints。这就是我的代码现在的样子:

    public ArrayList getLocations() {
ArrayList<OverlayItem> locations = new ArrayList<OverlayItem>();
/* open SQLite database aanmaken als deze al dan niet bestaat */

SQLiteDatabase myDB = openOrCreateDatabase(DATABASE_NAME, Context.MODE_PRIVATE, null);
SharedPreferences preferences = getSharedPreferences("data", 0);
String route_id = String.valueOf( preferences.getInt("route_id", 0));

String[] resultColumns = new String[] { "_id", "route_id","naam", "lng", "lat" };
String whereClause = "route_id=?";
String[] whereArgs = new String[] {route_id};

Cursor cursor = myDB.query(DATABASE_TABLE_LOCATIES, resultColumns, whereClause,
whereArgs, null, null, null, null);

cursor.moveToFirst();
do {
String naam = cursor.getString(2);
Double lat = cursor.getDouble(4);
Double lon = cursor.getDouble(3);
GeoPoint point = new GeoPoint((int) (lat * 1E6),(int) (lon * 1E6));
locations.add(new OverlayItem(point, naam,naam));
} while (cursor.moveToNext());



return locations;
}

public void onCreate(Bundle savedInstanceState) {
InterestingLocations funPlaces = new InterestingLocations(marker);
mapView.getOverlays().add(getLocations);
}

此代码将我所有的指针同时放在 mapView 上。将每个指针放在 map 上时,我希望有一点延迟。我怎么能这样做?

提前致谢

最佳答案

首先定义全局变量,

private Timer myTimer;

onCreate() 方法中添加:

myTimer = new Timer();
myTimer.schedule(new TimerTask() {
@Override
public void run() {
TimerMethod();
}

}, 0, 1000);

}

并在类中添加这个函数:

private void TimerMethod()
{
this.runOnUiThread(Timer_Tick);
}

并将其定义为全局变量:

private Runnable Timer_Tick = new Runnable() {
public void run() {

//here is your job, instead of writing this [mapView.getOverlays().add(getLocations);]

//you have to create a loop for the list returned by getLocations() to add them in the timer one by one
}
};

关于Android在谷歌地图上延迟添加地理点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10164936/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com