更新 addMarker google 地图 2v 时出错
Error renewing addMarker google Maps 2v
嗯,我一直在做很多尝试,来更新我的 google 地图的 addMarker。
当我启动 activity 时,图标出现在地图中,但是当在线程中再次调用该函数时出现错误...
我不知道我能做什么,我尝试将 addMarker 声明为 Marker var,然后在线程中声明 var.remove() 并放置另一个 addMarker,我得到了同样的错误...
这是map_activityxml
<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>
我的map_activityclass
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));
}
}
我想知道问题出在哪里...
10-12 16:59:37.427 25539-25539/com.gpslocmex.locmex E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.util.AndroidRuntimeException: { what=0 when=-1ms } This message is already in use.
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:285)
at android.os.Handler.sendMessageAtTime(Handler.java:473)
at android.os.Handler.postAtTime(Handler.java:285)
at com.google.maps.api.android.lib6.d.cm.c(Unknown Source)
at com.google.maps.api.android.lib6.d.cm.b(Unknown Source)
at com.google.maps.api.android.lib6.d.et.a(Unknown Source)
at com.google.android.gms.maps.internal.j.onTransact(SourceFile:167)
at android.os.Binder.transact(Binder.java:326)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addMarker(Unknown Source)
at com.google.android.gms.maps.GoogleMap.addMarker(Unknown Source)
at com.gpslocmex.locmex.Mapa_activity.renovarmarcador(Mapa_activity.java:218)
at com.gpslocmex.locmex.Mapa_activity.handleMessage(Mapa_activity.java:161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
错误抛出是因为您调用了一次new Message()
并多次发送消息。
public void run() {
while (!Mapa_activity.this.isFinishing()) {
Message msgObj = new Message();
handler.sendMessage(msgObj);
try {
System.out.println("****30s");
Thread.sleep(30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}//while
}
嗯,我一直在做很多尝试,来更新我的 google 地图的 addMarker。
当我启动 activity 时,图标出现在地图中,但是当在线程中再次调用该函数时出现错误...
我不知道我能做什么,我尝试将 addMarker 声明为 Marker var,然后在线程中声明 var.remove() 并放置另一个 addMarker,我得到了同样的错误...
这是map_activityxml
<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>
我的map_activityclass
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));
}
}
我想知道问题出在哪里...
10-12 16:59:37.427 25539-25539/com.gpslocmex.locmex E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.util.AndroidRuntimeException: { what=0 when=-1ms } This message is already in use.
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:285)
at android.os.Handler.sendMessageAtTime(Handler.java:473)
at android.os.Handler.postAtTime(Handler.java:285)
at com.google.maps.api.android.lib6.d.cm.c(Unknown Source)
at com.google.maps.api.android.lib6.d.cm.b(Unknown Source)
at com.google.maps.api.android.lib6.d.et.a(Unknown Source)
at com.google.android.gms.maps.internal.j.onTransact(SourceFile:167)
at android.os.Binder.transact(Binder.java:326)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addMarker(Unknown Source)
at com.google.android.gms.maps.GoogleMap.addMarker(Unknown Source)
at com.gpslocmex.locmex.Mapa_activity.renovarmarcador(Mapa_activity.java:218)
at com.gpslocmex.locmex.Mapa_activity.handleMessage(Mapa_activity.java:161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
错误抛出是因为您调用了一次new Message()
并多次发送消息。
public void run() {
while (!Mapa_activity.this.isFinishing()) {
Message msgObj = new Message();
handler.sendMessage(msgObj);
try {
System.out.println("****30s");
Thread.sleep(30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}//while
}