2013-05-04 29 views
0

我正在開發一個場景,在該場景中,我必須在列表視圖中顯示最近位置的地址,該列表視圖位於MapActivity上。但是,在成功運行我的代碼後,該列表將不會出現在MapActivity上。MapActivity未顯示列表

這裏是我的代碼:

public class GMapActivity extends com.google.android.maps.MapActivity implements OnClickListener{ 

    MapView _mapView; 
    private static int latitudeE6 = 37985339; 
    private static int longitudeE6 = 23716735; 
    private GpsListener _gpsLister=new GpsListener(); 
    List<Overlay> overlayList; 

    MapController controller; 

    Button _cancelBtn; 

    String returnAddress = ""; 

    ListView locationListView; 
    ArrayList<String> locationAddressArrayList=new ArrayList<String>(); 
    ArrayAdapter<String> locationAdapter; 

    LocationListAdapter locationListAdapter; 

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

     _mapView=(MapView)findViewById(R.id.mapView); 
     _mapView.setBuiltInZoomControls(true); 

     _cancelBtn=(Button)findViewById(R.id.cancel_button); 
     _cancelBtn.setOnClickListener(this); 

     locationListView=(ListView)findViewById(R.id.location_listview); 
     /*locationAdapter=new ArrayAdapter<String>(GMapActivity.this, android.R.layout.simple_list_item_1, locationAddressArrayList);*/ 
     locationListAdapter=new LocationListAdapter(GMapActivity.this, locationAddressArrayList); 
     locationAddressArrayList.add("RNT Marg"); 
     locationAddressArrayList.add("RNT Marg"); 
     locationAddressArrayList.add("RNT Marg"); 
     locationAddressArrayList.add("RNT Marg"); 
     locationAddressArrayList.add("RNT Marg"); 
     locationAddressArrayList.add("RNT Marg"); 
     locationListView.setAdapter(locationListAdapter); 
     ///////////////START GPS///////////////// 
     if(Constant.isGpsStarted==false){ 
      startGPS(); 
      latitudeE6=(int)Constant.latitudeValue; 
      longitudeE6=(int)Constant.longitudeValue; 
     } 
     //GetAddress(Constant.latitudeValue, Constant.longitudeValue); 
     ///////////////////////////////////////// 

     ////////////////////////////////GET NEAREST LOCATIONS///////////////////////////// 
     LocationManager locationManager = (LocationManager) GMapActivity.this 
       .getSystemService(Context.LOCATION_SERVICE); 
     LocationListener locationListener = new LocationListener() { 
      public void onStatusChanged(String provider, int status, 
        Bundle extras) { 
      } 

      public void onProviderEnabled(String provider) { 
      } 

      public void onProviderDisabled(String provider) { 
      } 

      public void onLocationChanged(Location location) { 
       Double l1 = location.getLatitude(); 
       Double l2 = location.getLongitude(); 
       //GetAddress(l1, l2); 
      } 
     }; 

     locationManager.requestLocationUpdates(
       LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 
     ////////////////////////////////////////////////////////////////////////////////// 
     List mapOverlays = _mapView.getOverlays(); 
     Drawable drawable = this.getResources().getDrawable(R.drawable.mapping); 
     CustomItemizedOverlay itemizedOverlay = 
       new CustomItemizedOverlay(drawable, this); 

     GeoPoint point = new GeoPoint(latitudeE6, longitudeE6); 
     OverlayItem overlayitem = 
       new OverlayItem(point, ""+Constant.latitudeValue, ""+Constant.longitudeValue); 

     itemizedOverlay.addOverlay(overlayitem); 
     mapOverlays.add(itemizedOverlay); 

     MapController mapController = _mapView.getController(); 

     mapController.animateTo(point); 
     mapController.setZoom(6); 

     /*overlayList = _mapView.getOverlays(); 
     Drawable drawable = this.getResources().getDrawable(R.drawable.mapping); 
     CustomPinPoint itemizedoverlay = new CustomPinPoint(drawable,this); 


     double lat_coordinates[] ={27.700556,28.2642635,30.0018168,29.776669,29.4096819,29.4560611}; 
     double lng_coordinates[] ={85.3630,83.9735195,80.7382742,81.2518833,81.8115051,80.5403779}; 
     String place_name[] ={"kathmandu","Pokhara","Darchula","Bajhang","Bajura","Baitadi"}; 
     String place_info[] ={"Its an capital of Nepal","Its and tourist place of Nepal","Its one of the beautiful place in country side","CHD District Target:10 51,960, VDCs/Muncipalities reported:41/41","CHD District Target: 71,280, VDCs/Muncipalities reported: 47/47","CHD District Target:10 51,960, VDCs/Muncipalities reported:41/41","CHD District Target: 71,280, VDCs/Muncipalities reported: 7/7","CHD District Target:10 21,960, VDCs/Muncipalities reported:44/41","CHD District Target: 33,3123, VDCs/Muncipalities reported: 47/47"}; 

     try{ 
      for(int i=0; i<place_name.length; i++) 
      { 
       GeoPoint point = new GeoPoint((int)(lat_coordinates[i]*1E6),(int)(lng_coordinates[i]*1E6)); 
       OverlayItem overlayitem = new OverlayItem(point, place_name[i], place_info[i]); 
       itemizedoverlay.addOverlay(overlayitem); 
      } 
     }catch(NullPointerException e){ 
      e.getStackTrace(); 

     } 
     finally{ 
      overlayList.add(itemizedoverlay); 
     } 

     controller = _mapView.getController(); 
     controller.animateTo(new GeoPoint((int)(lat_coordinates[0]*1E6),(int)(lng_coordinates[0]*1E6))); 
     controller.setZoom(8);*/ 
    } 

    //START GPS 
    public void startGPS(){ 
     Constant.isGpsStarted = true; 
     _gpsLister.startGpsCallBack(GMapActivity.this); 
     _gpsLister.stopGpsCallBack(); 
     _gpsLister.startGpsCallbackAgain(GMapActivity.this); 
    } 

    @Override 
    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    } 

    public void onClick(View v) { 
     switch (v.getId()) { 
     case R.id.cancel_button: 
      this.finish(); 
      break; 

     default: 
      break; 
     } 
    } 

    public void getNearestLocations(){ 

    } 

    private void GetAddress(final Double lat, final Double lon) { 
     Constant.progressDialog = ProgressDialog.show(GMapActivity.this,"", "Please wait..."); 
     new Thread(){ 
      public void run() { 
       Geocoder geocoder = new Geocoder(GMapActivity.this, Locale.ENGLISH); 
       List<Address> addresses = null; 
       try { 
        addresses = geocoder.getFromLocation(lat, lon, 1); 
        if (!addresses.equals(null)) { 
         Address returnedAddress = addresses.get(0); 
         StringBuilder strReturnedAddress = new StringBuilder("\n"); 
         for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) { 

          locationAddressArrayList.add((String)returnedAddress.getAddressLine(i)); 

          strReturnedAddress 
          .append(returnedAddress.getAddressLine(i)).append(
            "\n"); 
         } 
         returnAddress = "Around: " + strReturnedAddress.toString(); 
        } else { 
         returnAddress = "No Address returned!"; 
        } 
       } catch (IOException e) { 
        e.printStackTrace(); 
        returnAddress = "Location: https://maps.google.co.in/maps?hl=en&q=" + lat 
          + "," + lon; 
       } catch (NullPointerException e) { 
        e.printStackTrace(); 
        returnAddress = lat + "," + lon; 
       } 

       runOnUiThread(new Runnable() { 
        public void run() { 
         locationAdapter.notifyDataSetChanged(); 
         locationListView.setAdapter(locationAdapter); 
         Constant.progressDialog.cancel(); 
        } 
       }); 
      }; 
     }.start(); 

     // return returnAddress; 
    } 
} 
+0

嗨,任何人都可以回答這個......? – 2013-05-04 09:55:23

+0

嗨,我已經解決它自己。事實上,這是我的XML中的問題。 – 2013-05-04 11:05:08

回答

2

該庫已過時。

從2012年12月3日起,Google Maps Android API版本1已被正式棄用。這意味着從2013年3月18日起,您將不再能夠爲此版本請求API密鑰。 Google地圖Android API v1不會添加任何新功能。但是,使用v1的應用程序將繼續在設備上運行。鼓勵現有和新開發人員使用Google Maps Android API v2