2013-03-19 49 views
1

我已經在android中使用過使用過的map api v2。我可以使用groundoverlay在地圖上加載圖像,但圖像顯示非常小。我需要將圖像完全加載到地圖視圖上,例如覆蓋整個地圖區域。有人可以幫我這個.. Here is the image我想加載地圖 三江源提前結束了...無法在谷歌地圖上顯示圖像api v2在android中使用groundOverlay

public class GroundOverlayDemoActivity extends FragmentActivity implements OnSeekBarChangeListener { 

    private static final int TRANSPARENCY_MAX = 100; 
    private static final LatLng NEWARK = new LatLng(40.714086, -74.228697); 
    //private static final LatLng NEWARK = new LatLng(18.5236, 73.8478); 

    private GoogleMap mMap; 
    private GroundOverlay mGroundOverlay; 
    private SeekBar mTransparencyBar; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.ground_overlay_demo); 

     mTransparencyBar = (SeekBar) findViewById(R.id.transparencySeekBar); 
     mTransparencyBar.setMax(TRANSPARENCY_MAX); 
     mTransparencyBar.setProgress(0); 

     setUpMapIfNeeded(); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     setUpMapIfNeeded(); 
    } 

    private void setUpMapIfNeeded() { 
     if (mMap == null) { 
      mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) 
       .getMap(); 
      if (mMap != null) { 
       setUpMap(); 
      } 
     } 
    } 

    private void setUpMap() { 
     mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(NEWARK, 8)); 


     mGroundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.omnistar_hp)).anchor(0, 1).position(NEWARK, 8600000f, 6500000f)); 
    //.position(NEWARK, 9999999.0f));//, 10000000f)); 

     mTransparencyBar.setOnSeekBarChangeListener(this); 
    } 

    @Override 
    public void onStopTrackingTouch(SeekBar seekBar) {} 

    @Override 
    public void onStartTrackingTouch(SeekBar seekBar) {} 

    @Override 
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 
     if (mGroundOverlay != null) { 
      mGroundOverlay.setTransparency((float) progress/(float) TRANSPARENCY_MAX); 
     } 
    } 
} 
+0

我已經做了,只有婦女參與發展自己和它的工作原理完全我想,從來沒有崩潰的相同wid images..below是代碼 – 2013-03-22 05:31:51

回答

1
 import android.support.v4.app.FragmentActivity; 
     import android.support.v4.app.FragmentManager; 
     import android.util.Log; 
     import android.util.TypedValue; 
     import android.view.Menu; 
     import android.view.MenuItem; 





     public class MapDisplayActivity extends FragmentActivity implements   OnMapClickListener, OnMapLongClickListener { 
     private GoogleMap myMap; 

     private static LatLng SearchPlace; 
     double Latitude; 
     double Longitiude; 
     List<Address> addresses; 

     //Address location; 
     BitmapDescriptor image; 
    /// private static final LatLng NEWARK = new LatLng(18.5236, 73.8478); 


      private GroundOverlay mGroundOverlay; 

      //this is for omnistarg dont touch this 
      LatLng southwest= new LatLng(-85.513398,-178.242187); 

      LatLng northeast= new LatLng(85.513398,178.242187); 

     float zoomValue = 7.0f; 
     private String SpinerValue; 
     private Bitmap bitmap; 
      @Override 
      `enter code here`protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.mapactivity); 
     //VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024); 
     Log.v("Utils", "Max mem in MB : " + (Runtime.getRuntime().maxMemory()/(1024*1024))); 
     Runtime.getRuntime().maxMemory(); 
     Debug.getNativeHeapSize(); 

     initActionBar(); 

     //textInfo=(TextView)findViewById(R.id.locinfo); 

      FragmentManager myFragmentManager = getSupportFragmentManager(); 
      SupportMapFragment mySupportMapFragment 
      = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map); 
      myMap = mySupportMapFragment.getMap(); 





      // myMap.setMyLocationEnabled(true); 


      // myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 
      myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
      // myMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 
      //myMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); 


      myMap.setOnMapClickListener(this); 
      myMap.setOnMapLongClickListener(this); 
      myMap.getUiSettings().setZoomControlsEnabled(true); 
      myMap.getUiSettings().setMyLocationButtonEnabled(true); 

      Intent intent=getIntent(); 
      Latitude=intent.getDoubleExtra("Latitude", 0.000); 
      Longitiude=intent.getDoubleExtra("Longititude", 0.000); 
      SpinerValue=(String)intent.getStringExtra("SPINNERVALUE"); 

      SearchPlace = new LatLng(Latitude, Longitiude); 

      myMap.moveCamera(CameraUpdateFactory.newLatLng(SearchPlace)); 
      myMap.addMarker(new MarkerOptions().position(SearchPlace));//.title(PlaceName)); 
      drawImageOverMap(); 

//   BitmapFactory.Options opts=new BitmapFactory.Options(); 
//   opts.inDither=false;      //Disable Dithering mode 
//   opts.inPurgeable=true;   
//   opts.inSampleSize=8; 
//  Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.omnistar_g); 

    } 



    public void drawImageOverMap(){ 

      myMap.animateCamera(CameraUpdateFactory.zoomTo(zoomValue)); 

       //image =BitmapDescriptorFactory.fromResource(R.drawable.omnistar_g); 
      if(SpinerValue.equalsIgnoreCase("TEC")){ 
       //centerpoint_vrs 
       bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.omnistar_two); 


       BitmapFactory.Options o2 = new BitmapFactory.Options(); 
       o2.inSampleSize=4; 
       image=BitmapDescriptorFactory.fromBitmap(bitmap); 
        LatLngBounds bounds =new LatLngBounds(southwest, northeast); 


        mGroundOverlay = myMap.addGroundOverlay(new GroundOverlayOptions() 
         .image(image) 
         //.transparency(0.4f) 

         //.anchor(0, 1) 
         .positionFromBounds(bounds)); 

      } 
      else if(SpinerValue.equalsIgnoreCase("OmniSTARG2")){ 
       bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.omnistar_g_img); 


       BitmapFactory.Options o2 = new BitmapFactory.Options(); 
       o2.inSampleSize=4; 
       image=BitmapDescriptorFactory.fromBitmap(bitmap); 
        LatLngBounds bounds =new LatLngBounds(southwest, northeast); 


        mGroundOverlay = myMap.addGroundOverlay(new GroundOverlayOptions() 
         .image(image) 
         .transparency(0.4f) 

         //.anchor(0, 1) 
         .positionFromBounds(bounds)); 
      } 
      else if(SpinerValue.equalsIgnoreCase("OmniStarHP")){ 
       bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.omnistar_hp_two); 


       BitmapFactory.Options o2 = new BitmapFactory.Options(); 
       o2.inSampleSize=4; 
       image=BitmapDescriptorFactory.fromBitmap(bitmap); 
        LatLngBounds bounds =new LatLngBounds(southwest, northeast); 


        mGroundOverlay = myMap.addGroundOverlay(new GroundOverlayOptions() 
         .image(image) 
         .transparency(0.4f) 

         //.anchor(0, 1) 
         .positionFromBounds(bounds)); 
      } 
      ///////////////////////////////////////////// 
      else if(SpinerValue.equalsIgnoreCase("OmniStarVBS")){ 
       bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.omnistar_vbs_two); 


       BitmapFactory.Options o2 = new BitmapFactory.Options(); 
       o2.inSampleSize=4; 
       image=BitmapDescriptorFactory.fromBitmap(bitmap); 
        LatLngBounds bounds =new LatLngBounds(southwest, northeast); 


        mGroundOverlay = myMap.addGroundOverlay(new GroundOverlayOptions() 
         .image(image) 
         .transparency(0.4f) 

         //.anchor(0, 1) 
         .positionFromBounds(bounds)); 

      } 
      else if(SpinerValue.equalsIgnoreCase("OmniSTARXP")){ 
       bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.omnistar_xp_two); 


       BitmapFactory.Options o2 = new BitmapFactory.Options(); 
       o2.inSampleSize=4; 
       image=BitmapDescriptorFactory.fromBitmap(bitmap); 
        LatLngBounds bounds =new LatLngBounds(southwest, northeast); 


        mGroundOverlay = myMap.addGroundOverlay(new GroundOverlayOptions() 
         .image(image) 
         .transparency(0.4f) 

         //.anchor(0, 1) 
         .positionFromBounds(bounds)); 
      } 
      else if(SpinerValue.equalsIgnoreCase("RTXStandardviaCellular")){ 
       //rtxcell 
       bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.rtx_cell_two); 


       BitmapFactory.Options o2 = new BitmapFactory.Options(); 
       o2.inSampleSize=4; 
       image=BitmapDescriptorFactory.fromBitmap(bitmap); 
        LatLngBounds bounds =new LatLngBounds(southwest, northeast); 


        mGroundOverlay = myMap.addGroundOverlay(new GroundOverlayOptions() 
         .image(image) 
         .transparency(0.3f) 

         //.anchor(0, 1) 
         .positionFromBounds(bounds)); 
      } 
      else if(SpinerValue.equalsIgnoreCase("RTXFastviaSatellite")){ 
       //rtxfast.png 
       bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.rtx_fast_two); 


       BitmapFactory.Options o2 = new BitmapFactory.Options(); 
       o2.inSampleSize=4; 
       image=BitmapDescriptorFactory.fromBitmap(bitmap); 
        LatLngBounds bounds =new LatLngBounds(southwest, northeast); 


        mGroundOverlay = myMap.addGroundOverlay(new GroundOverlayOptions() 
         .image(image) 
         .transparency(0.3f) 

         //.anchor(0, 1) 
         .positionFromBounds(bounds)); 
      } 
      else if(SpinerValue.equalsIgnoreCase("RTXStandardviaSatellite")){ 
       //rtxsat.png 
       bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.rtx_sat_two); 


       BitmapFactory.Options o2 = new BitmapFactory.Options(); 
       o2.inSampleSize=4; 
       image=BitmapDescriptorFactory.fromBitmap(bitmap); 
        LatLngBounds bounds =new LatLngBounds(southwest, northeast); 


        mGroundOverlay = myMap.addGroundOverlay(new GroundOverlayOptions() 
         .image(image) 
         .transparency(0.3f) 

         //.anchor(0, 1) 
         .positionFromBounds(bounds)); 
      } 
      else if(SpinerValue.equalsIgnoreCase("VRSNow")){ 
       //vrsnowtec.png 
       bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.vrsnow_tec_two); 


       BitmapFactory.Options o2 = new BitmapFactory.Options(); 
       o2.inSampleSize=4; 
       image=BitmapDescriptorFactory.fromBitmap(bitmap); 
        LatLngBounds bounds =new LatLngBounds(southwest, northeast); 


        mGroundOverlay = myMap.addGroundOverlay(new GroundOverlayOptions() 
         .image(image) 
         .transparency(0.3f) 

         //.anchor(0, 1) 
         .positionFromBounds(bounds)); 
      } 
         // InputStream is =getClass().getResourceAsStream(omnistar_g); 
         //bitmap = readAssetsBitmap("omnistar_g.png"); 
         //bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.trimble_screen_logo); 
         //bitmap=bitmap(is); 


         //image =BitmapDescriptorFactory.fromResource(R.drawable.omnistar_g); 


           bitmap.recycle(); 
           bitmap = null; 
           System.gc(); 
           Runtime.getRuntime().gc(); 



    } 
+0

我唯一面臨的問題是在加載大尺寸圖像後,由於堆尺寸超過圖像尺寸而導致崩潰..我縮小了圖像尺寸並使用了它。也做了一些代碼中的東西,你可以參考上面哪些有助於避免崩潰應用程序使用圖像..感謝谷歌文檔它幫助了我很多,最後我做到了.. – 2013-03-22 05:44:16

相關問題