2011-09-03 52 views
1

在我的應用程序我有一個重疊的引腳,標誌着一個興趣點。我也想用mylocationoverlay顯示用戶當前的位置。然而,當我嘗試這兩個我從我的堆棧跟蹤得到這個錯誤結合,當我的手機我可以將MyLocationOverlay與另一個覆蓋層一起使用嗎?

09-03 12:38:22.345: WARN/System.err(361): IOException processing: 26 
    java.io.IOException: Server returned: 3 
    at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115): 
    at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473) 
at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117) 
at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702) 
at java.lang. 

Thread.run(Thread.java:1019) 

這裏上運行它,它崩潰是我使用的代碼。我在onCreate方法創建的mylocationoverlay和我在重裝異步任務創建

public class Maps extends MapActivity { 



    ProgressDialog progressDialog; 
    private ArrayList<Pins> mList; 
    final public static int[] pincolorstar = { R.drawable.pinredstar, 
      R.drawable.pinlitebluestar, R.drawable.pinblackstar, 
      R.drawable.pindarkbluestar, R.drawable.pingreenstar, 
      R.drawable.pinlitegreenstar, R.drawable.pinorangestar, 
      R.drawable.pinyellowstar, R.drawable.pinwhitestar, 
      R.drawable.pinpurplestar }; 
    static boolean setSatellite, setHybrid = false; 
    @Override 
    protected void onPause() { 
     // TODO Auto-generated method stub 
     super.onPause(); 
    } 

    @Override 
    protected void onResume() { 
     // TODO Auto-generated method stub 
     super.onResume(); 
    } 
    @Override 
    protected void onCreate(Bundle icicle) { 
     // TODO Auto-generated method stub 

     super.onCreate(icicle); 
     try { 
      setContentView(R.layout.maps); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     final SharedPreferences prefs = getSharedPreferences("Settings", 0); 
     final int hour = prefs.getInt("Hour_Range", 4); 
     new Reload().execute(); 
     Button done = (Button) findViewById(R.id.btnDone); 
     done.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       finish(); 
      } 
     }); 
     Button change = (Button) findViewById(R.id.btnChangeTime); 
     change.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       final int hour = prefs.getInt("Hour_Range", 4); 
       LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       View layout = inflater.inflate(R.layout.your_dialog, 
         (ViewGroup) findViewById(R.id.relativeLayoutMaps)); 

       final SeekBar seekBar = (SeekBar) layout 
         .findViewById(R.id.seekBarChangeTime); 
       final TextView ChangeTexthour = (TextView) layout 
         .findViewById(R.id.tVChangeableTime); 
       ChangeTexthour.setText(prefs.getString("Hour_notification", 
         "Only most recent positions")); 
       seekBar.setProgress(hour); 
       OnSeekBarChangeListener yourSeekBarListener = new OnSeekBarChangeListener() { 

        @Override 
        public void onStopTrackingTouch(SeekBar seekBar) { 

        } 

        @Override 
        public void onStartTrackingTouch(SeekBar seekBar) { 

        } 

        @Override 
        public void onProgressChanged(SeekBar seekBar, 
          int progress, boolean fromUser) { 
         ChangeTexthour 
           .setText(getResources() 
             .getString(
               R.string.showlocationsforthelastxhours1) 
             + " " 
             + progress 
             + " " 
             + getResources() 
               .getString(
                 R.string.showlocationsforthelastxhours2)); 

        } 
       }; 

       seekBar.setOnSeekBarChangeListener(yourSeekBarListener); 

       AlertDialog.Builder builder = new AlertDialog.Builder(Maps.this) 
         .setView(layout) 
         .setPositiveButton(
           getResources().getString(R.string.Cancel), null) 
         .setNegativeButton("Set", 
           new DialogInterface.OnClickListener() { 

            @Override 
            public void onClick(DialogInterface dialog, 
              int which) { 

             SharedPreferences.Editor editor = prefs 
               .edit(); 
             editor.putString(
               "Hour_notification", 
               getResources() 
                 .getString(
                   R.string.showlocationsforthelastxhours1) 
                 + " " 
                 + seekBar.getProgress() 
                 + " " 
                 + getResources() 
                   .getString(
                     R.string.showlocationsforthelastxhours2)); 
             editor.putInt("Hour_Range", 
               seekBar.getProgress()); 
             editor.commit(); 
             new Reload().execute(); 
            } 
           }); 
       AlertDialog alertDialog = builder.create(); 
       alertDialog.show(); 

      } 
     }); 
     Button displayChange = (Button) findViewById(R.id.btnDisplayChange); 
     displayChange.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       AlertDialog.Builder builder = new AlertDialog.Builder(Maps.this) 
         .setMessage("Map Display Mode") 
         .setPositiveButton("Map", 
           new DialogInterface.OnClickListener() { 

            @Override 
            public void onClick(DialogInterface dialog, 
              int which) { 
             setSatellite = false; 
             setHybrid = false; 
             new Reload().execute(); 
            } 
           }) 
         .setNeutralButton("Satellite", 
           new DialogInterface.OnClickListener() { 

            @Override 
            public void onClick(DialogInterface dialog, 
              int which) { 
             setSatellite = true; 
             setHybrid = false; 
             new Reload().execute(); 

            } 
           }) 
         .setNegativeButton("Hybrid", 
           new DialogInterface.OnClickListener() { 

            @Override 
            public void onClick(DialogInterface dialog, 
              int which) { 
             setHybrid = true; 
             setSatellite = false; 
             new Reload().execute(); 
            } 
           }); 
       AlertDialog alertDialog = builder.create(); 
       alertDialog.show(); 
      } 
     }); 
     MapView mapView=(MapView) findViewById(R.id.mapView); 
     List<Overlay> overlays=mapView.getOverlays(); 
     MyLocationOverlay myLocationOverlay=new MyLocationOverlay(Maps.this, mapView); 
     myLocationOverlay.enableMyLocation(); 
     overlays.add(myLocationOverlay); 
    } 

    @Override 
    protected boolean isRouteDisplayed() { 
     return false; 
    } 

    private class Pins { 
     private String name; 
     private String time; 
     private String id; 
     private boolean mostrecent; 
     private Double longitude; 
     private Double latitude; 

     public Pins(String time, String id, String mostrecent, 
       Double longitude, Double latitude) { 
      this.time = time; 
      this.id = id; 

      this.longitude = longitude; 
      this.latitude = latitude; 
      boolean active = false; 
      if (mostrecent.equals("1")) 
       active = true; 
      else 
       active = false; 
      this.mostrecent = active; 
     } 

     public String getName() { 
      return name; 
     } 

     public String getTime() { 
      return time; 
     } 

     public String getId() { 
      return id; 
     } 

     public boolean getMostRecent() { 
      return mostrecent; 
     } 

     public Double getLongitude() { 
      return longitude; 
     } 

     public Double getLatitude() { 
      return latitude; 
     } 

     public void setName(String name) { 
      this.name = name; 
     } 

    } 

    public class Reload extends AsyncTask<Void, Void, Void> { 

     @Override 
     protected Void doInBackground(Void... params) { 
      final SharedPreferences prefs = getSharedPreferences("Settings", 0); 
      final int hour = prefs.getInt("Hour_Range", 4); 
      int followsize = 0; 
      for (int i = 0; i < ImTracking.ping.length; i++) { 
       followsize += ImTracking.ping[i]; 
      } 
      String[] ids = new String[followsize]; 
      int counter = 0; 
      for (int i = 0; i < ImTracking.ping.length; i++) { 
       if (ImTracking.ping[i] == 1) { 
        ids[counter] = ImTracking.pList.get(i).getid(); 
        counter++; 
       } 
      } 
      JSONArray users = new JSONArray(Arrays.asList(ids)); 

      HttpParams httpParams = new BasicHttpParams(); 
      // 30seconds and it stops 
      HttpConnectionParams.setConnectionTimeout(httpParams, 30000); 
      HttpConnectionParams.setSoTimeout(httpParams, 30000); 
      DefaultHttpClient httpclient = new DefaultHttpClient(httpParams); 
      HttpPost httpost = new HttpPost(
        "https://iphone-radar.com/gps/gps_locations_fetch"); 

      JSONObject holder = new JSONObject(); 

      try { 
       holder.put("userids", users); 
       holder.put("range", hour); 
       Calendar c=Calendar.getInstance(); 
       TimeZone tz=c.getTimeZone(); 
       Date now=new Date(); 
       int offsetFromUtc = tz.getOffset(now.getTime())/1000; 
       holder.put("timezone", offsetFromUtc); 
       StringEntity se = new StringEntity(holder.toString()); 
       httpost.setEntity(se); 
       httpost.setHeader("Accept", "application/json"); 
       httpost.setHeader("Content-type", "application/json"); 

       ResponseHandler responseHandler = new BasicResponseHandler(); 
       String response = httpclient.execute(httpost, responseHandler); 
       org.json.JSONObject obj = new org.json.JSONObject(response); 
       JSONArray tracking_users = obj.getJSONArray("d"); 
       ArrayList<Pins> mList = new ArrayList<Pins>(); 
       int minLat = Integer.MAX_VALUE; 
       int maxLat = Integer.MIN_VALUE; 
       int minLon = Integer.MAX_VALUE; 
       int maxLon = Integer.MIN_VALUE; 
       for (int i = 0; i < tracking_users.length(); i++) { 
        JSONObject user = tracking_users.getJSONObject(i); 
        Pins pin = new Pins(user.getString("time"), 
          user.getString("user_id"), 
          user.getString("most_recent"), 
          user.getDouble("longitude"), 
          user.getDouble("latitude")); 
        maxLat = (int) Math.max(user.getDouble("latitude") * 1E6, 
          maxLat); 
        minLat = (int) Math.min(user.getDouble("latitude") * 1E6, 
          minLat); 
        maxLon = (int) Math.max(user.getDouble("longitude") * 1E6, 
          maxLon); 
        minLon = (int) Math.min(user.getDouble("longitude") * 1E6, 
          minLon); 

        mList.add(pin); 
       } 
       MapView mapView = (MapView) findViewById(R.id.mapView); 
       mapView.setSatellite(setSatellite); 
       mapView.setStreetView(setHybrid); 
       List<Overlay> mapOverlays = mapView.getOverlays(); 

       for (int i = 0; i < mList.size(); i++) { 
        Drawable drawable = null; 
        for (int k = 0; k < ImTracking.pList.size(); k++) { 
         if (mList.get(i).getId() 
           .equals(ImTracking.pList.get(k).getid())) { 
          mList.get(i).setName(
            ImTracking.pList.get(k).getName()); 
          if (mList.get(i).getMostRecent()) { 
           drawable = Maps.this.getResources() 
             .getDrawable(
               pincolorstar[ImTracking.pList 
                 .get(k).getPosition()]); 

          } else { 
           drawable = Maps.this 
             .getResources() 
             .getDrawable(
               ImTracking.pincolors[ImTracking.pList 
                 .get(k).getPosition()]); 
          } 
         } 
        } 

        HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(
          drawable, mapView); 
        GeoPoint myPoint = new GeoPoint((int) (mList.get(i) 
          .getLatitude() * 1E6), (int) (mList.get(i) 
          .getLongitude() * 1E6)); 
        OverlayItem overlayitem = new OverlayItem(myPoint, mList 
          .get(i).getName(), mList.get(i).getTime()); 
        itemizedoverlay.addOverlay(overlayitem); 
        mapOverlays.add(itemizedoverlay); 
       } 

       MapController mc = mapView.getController(); 
       mc.zoomToSpan(Math.abs(maxLat - minLat), 
         Math.abs(maxLon - minLon)); 

       mc.animateTo(new GeoPoint((maxLat + minLat)/2, 
         (maxLon + minLon)/2)); 

      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
      progressDialog.dismiss(); 
      return null; 
     } 

     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      progressDialog = ProgressDialog.show(Maps.this, "", 
        "Updating Data..."); 
     } 
    } 

感謝您的幫助

回答

0

您的例外似乎不會有什麼做的疊加其他疊加,而是在從Google地圖服務器檢索地圖圖塊時遇到一些問題。 Here is a sample project演示MyLocationOverlay(用於指南針玫瑰)和自定義疊加。

+0

這個異常是一個警告,我沒有使用API​​調試器密鑰。問題是,它有時會起作用,我可以看到我的針腳和我的位置,有時它只是崩潰。沒有錯誤消息,並且不會一直髮生。在調試器中,它使我的程序轉到找不到源頁面。當我從地圖視圖轉到衛星視圖時,該程序也頻繁崩潰。 –

相關問題