我已经做了很多尝试,为我的谷歌地图做了一个更新addMarker的循环。
当我开始活动时,图标会出现在地图中,但是当在线程中再次调用该函数时,我会收到错误...
我不知道我能做什么,我尝试将addMarker声明为Marker var,并在线程声明var.remove()并添加另一个addMarker,我得到同样的错误......
这是map_activity xml
for
我的map_activity类
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
<include layout="@layout/opciones_menu" android:id="@+id/opciones_menu"/>
</RelativeLayout>
我想知道问题出在哪里......
public class Mapa_activity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapa_activity);
mMap = ((SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//var global for updating the lat and lon
global=((Global)getApplicationContext());
Thread background = new Thread(new Runnable() {
private final Handler handler = new Handler() {
public void handleMessage(Message msg) {
renovarMarcador();
}
};
// After call for background.start this run method call
public void run() {
Message msgObj = new Message();
while(!Mapa_activity.this.isFinishing())
{
handler.sendMessage(msgObj);
try {
System.out.println("****30s");
Thread.sleep(30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}//while
}
});
// Start Thread
background.start();
//After call start method thread called run Method
}
@Override
protected void onResume() {
super.onResume();
renovarmarcador();
}
public void renovarmarcador(){
mMap.clear();
Double lat, lon;
lat = Double.parseDouble(global.gety(String.valueOf(NID)));
lon = Double.parseDouble(global.getx(String.valueOf(NID)));
System.out.println("LAT: " + lat + "\nLON: " + lon);
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(lat, lon);
mMap.addMarker(new MarkerOptions().position(latLng));
// Showing the current location in Google Map
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
}
答案 0 :(得分:1)
错误被抛出,因为您拨打CCSHA1
一次并多次发送邮件。
new Message()