使用* 1e6叠加项目以添加两个以上的项目

时间:2011-04-24 22:12:11

标签: android

在android中添加叠加项我想在地图视图中添加叠加项!!所以我走了

public void addOverLays(){

    String [] coordinates = {"30.084262490272522","31.33625864982605" ,"30.084123015403748", "51.5002" , "-0.1262","31.337149143218994"};
    double lat = 30.084262490272522, lat2 = 51.5002,lat3=30.084123015403748;
    double log = 31.33625864982605, log2 = -0.1262,log3=31.337149143218994;

    p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));


   p2 = new GeoPoint( (int) (lat2 * 1e6), (int) (log2 * 1e6));

   p3=new GeoPoint( (int) (lat3 * 1000000), (int) (log3 * 1000000));

    mapOverlays = mapView.getOverlays();
    drawable = this.getResources().getDrawable(R.drawable.ballon);
   drawable2 = this.getResources().getDrawable(R.drawable.dotred);

    drawable3 = this.getResources().getDrawable(R.drawable.icon);

        itemizedOverlay = new HelloItemizedOverlay(drawable,this);
    itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);        
    itemizedOverlay3 = new HelloItemizedOverlay(drawable3,this);    
    OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1");
   OverlayItem over2 = new OverlayItem(p2, "ulm", "over2");
    OverlayItem over3 = new OverlayItem(p3, "offff", "over3");

    itemizedOverlay.addOverlay(overlayitem);

    mapOverlays.add(itemizedOverlay);

    itemizedOverlay2.addOverlay(over2);
   mapOverlays.add(itemizedOverlay2);

    itemizedOverlay2.addOverlay(over3);
    mapOverlays.add(itemizedOverlay3);
 mc.setZoom(17); 
 //mc.animateTo(p);
}

>

<< 但是p3第三个超过项目迫使应用程序关闭< p3 = new GeoPoint((int)(lat3 * 1000000),(int)(log3 * 1000000));>看起来像1000000的错误!但我已经使用1e6和1E6,但它们是浮动的,1000000是整数所以该怎么办?!
这里的错误出现在DDMS>>

04-25 00:27:17.370: ERROR/AndroidRuntime(1788): Uncaught handler: thread main exiting due to uncaught exception
04-25 00:27:17.390: ERROR/AndroidRuntime(1788): java.lang.NullPointerException
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at com.google.android.maps.ItemizedOverlay.getItemsAtLocation(ItemizedOverlay.java:617)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at com.google.android.maps.ItemizedOverlay.getItemAtLocation(ItemizedOverlay.java:586)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at com.google.android.maps.ItemizedOverlay.handleMotionEvent(ItemizedOverlay.java:498)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at com.google.android.maps.ItemizedOverlay.onTouchEvent(ItemizedOverlay.java:572)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at com.google.android.maps.OverlayBundle.onTouchEvent(OverlayBundle.java:63)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:620)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at android.view.View.dispatchTouchEvent(View.java:3368)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:851)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:811)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:811)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:811)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:811)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1758)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at android.app.Activity.dispatchTouchEvent(Activity.java:1993)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1742)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1549)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at android.os.Looper.loop(Looper.java:123)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at android.app.ActivityThread.main(ActivityThread.java:3948)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at java.lang.reflect.Method.invoke(Method.java:521)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
04-25 00:27:17.390: ERROR/AndroidRuntime(1788):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

你得到什么样的错误?

这一行:

itemizedOverlay2.addOverlay(over3);

应该是:

itemizedOverlay3.addOverlay(over3);