3

当我调用这个 createMarker() 方法时,我得到了一个 IllegalArgumentException:

private void createMarker(GoogleMap map, MarkerOptions options, OnMarkerCreateListener listener) {
    Log.e("LazyMarker", "Options var val: "+options);
    Log.i("LazyMarker", "GoogleMap Value:"+map);
    Log.i("LazyMarker", "OnMarkerCreateListener Value:"+listener);
    marker = map.addMarker(options);
    //Log.i("LazyMarker", "The value of Marker is:"+map.addMarker(options));
    if (listener != null) {
        listener.onMarkerCreate(this);
    }
}

这是 logcat 输出:

06-14 11:40:38.627: I/OGT.RideTracking(25590): Map value is: com.google.android.gms.maps.GoogleMap@4249bd30
06-14 11:40:38.627: E/LazyMarker(25590): Options var val: com.google.android.gms.maps.model.MarkerOptions@4318baf8
06-14 11:40:38.627: I/LazyMarker(25590): GoogleMap Value:com.google.android.gms.maps.GoogleMap@4249bd30
06-14 11:40:38.627: I/LazyMarker(25590): OnMarkerCreateListener Value:null
06-14 11:40:38.637: D/AndroidRuntime(25590): Shutting down VM
06-14 11:40:38.637: W/dalvikvm(25590): threadid=1: thread exiting with uncaught exception (group=0x415d7438)
06-14 11:40:38.637: E/AndroidRuntime(25590): FATAL EXCEPTION: main
06-14 11:40:38.637: E/AndroidRuntime(25590): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.gpstracker/com.polaris.epicriders.Rides.RideTracking}: java.lang.IllegalArgumentException: no position in marker options
06-14 11:40:38.637: E/AndroidRuntime(25590):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2088)
06-14 11:40:38.637: E/AndroidRuntime(25590):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
06-14 11:40:38.637: E/AndroidRuntime(25590):    at android.app.ActivityThread.access$700(ActivityThread.java:139)
06-14 11:40:38.637: E/AndroidRuntime(25590):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
06-14 11:40:38.637: E/AndroidRuntime(25590):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-14 11:40:38.637: E/AndroidRuntime(25590):    at android.os.Looper.loop(Looper.java:137)
06-14 11:40:38.637: E/AndroidRuntime(25590):    at android.app.ActivityThread.main(ActivityThread.java:4918)
06-14 11:40:38.637: E/AndroidRuntime(25590):    at java.lang.reflect.Method.invokeNative(Native Method)
06-14 11:40:38.637: E/AndroidRuntime(25590):    at java.lang.reflect.Method.invoke(Method.java:511)
06-14 11:40:38.637: E/AndroidRuntime(25590):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
06-14 11:40:38.637: E/AndroidRuntime(25590):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
06-14 11:40:38.637: E/AndroidRuntime(25590):    at dalvik.system.NativeStart.main(Native Method)
06-14 11:40:38.637: E/AndroidRuntime(25590): Caused by: java.lang.IllegalArgumentException: no position in marker options

我的 MarkerOptions 和 GoogleMap 值不为空?问题在于这一行:

marker = map.addMarker(options);

当我评论应用程序上方的行时,它会继续进行下一个活动。我的问题是什么?任何帮助,将不胜感激。

4

2 回答 2

6
Caused by: java.lang.IllegalArgumentException: no position in marker options

显然,您MarkerOptions没有职位。请致电position()提供放置标记的位置。

于 2013-06-14T16:51:25.657 回答
0

它对我有用,

MarkerOptions mMarkerOptions = new MarkerOptions();
mMarkerOptions.position(new LatLng(lat, lang));
mMarkerOptions.anchor(0.5f, 0.5f);
于 2015-06-02T15:36:56.193 回答