我有一个计时器。每5分钟一班。在定时器运行方法中编写一个名为konumlarıAl的方法。这个方法从数据库中获取位置数据。当konumlarıAl运行时,HaritaKonumGoster正在调用方法。我想删除所有标记,并在地图上显示新的位置数据标记,而不刷新页面。
<标题> 我的代码private void HaritaKonumGoster() {
// TODO Auto-generated method stub
if (googleHarita == null) {
googleHarita = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.haritafragment))
.getMap();
if (googleHarita != null) {
googleHarita.clear();
if(mrks.size()!=0)
{
for (Marker marker: mrks) {
marker.remove();
}
mrks.clear();
}
googleHarita.setMyLocationEnabled(true);
LocationManager locationManager=(LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criteria=new Criteria();
String provider =locationManager.getBestProvider(criteria, true);
Location mylocation=locationManager.getLastKnownLocation(provider);
double latitude=0;
double longitude=0;
double mylatitude=0;
double myLongtitude=0;
//double latitude=enlem;
//double longitude=boylam;
if (mylocation != null){
mylatitude=mylocation.getLatitude();
myLongtitude=mylocation.getLongitude();
}
BitmapDescriptor bitmapDescriptor
= BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN);
try{
for (int i = 0; i < degiskenler.taksici.size(); i++) {
latitude=Double.parseDouble(degiskenler.taksici.get(i).enlem.trim());
longitude=Double.parseDouble(degiskenler.taksici.get(i).boylam.trim());
LatLng istanbulKoordinat = new LatLng(latitude,longitude);
Marker m= googleHarita.addMarker(new MarkerOptions().position(istanbulKoordinat).title("Kız Kulesi").icon(bitmapDescriptor));
googleHarita.moveCamera(CameraUpdateFactory.newLatLngZoom(istanbulKoordinat, 7));
mrks.add(m);
// Toast.makeText(getBaseContext(),"harita :)",Toast.LENGTH_LONG).show();
}
}
catch(Exception exception) {
Toast.makeText(getBaseContext(),"harita olmadı",Toast.LENGTH_LONG).show();
}
googleHarita.addMarker(new MarkerOptions().position(new LatLng(mylatitude, myLongtitude)).title("you hereeee"));
}
}
}
位置每5分钟更新一次方法
private void LocationUpdateEvery5minute() {
// TODO Auto-generated method stub
zamanlayici = new Timer();
yardimci = new Handler(Looper.getMainLooper());
zamanlayici.scheduleAtFixedRate(new TimerTask()
{
@Override
public void run(){
yardimci.post(new Runnable()
{
public void run()
{ Toast.makeText(getBaseContext(), "timera girdi",Toast.LENGTH_SHORT).show();
konumlarıAl();
}
});
}
}, 0, ZAMAN);
}
标题>
删除
标记 googleHarita.clear()
https://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.html clear ()
只需调用这个方法就足以移除地图上的所有标记。
然后,使用
添加标记googleHarita.addMarker()
http://developer.android.com/reference/com/google/android/gms/maps/model/Marker.html 例子
我认为你不需要刷新任何页面
您必须使用map.clear();这将帮助您从地图中删除所有标记,折线,多边形,叠加等。